Top answers

All subjects
Mentoring

Write a function s(n) that will return a list of the first n squares.

def s(n): ans=[] #This variable stores the list we will return. for i in range(n): #This is a for loop that will iterate n times. ans.append((i+1)**2) #This adds the (i+1)th square to the list, because ra...

Answered by Brodie M. Python tutor
593 Views

What is the difference between using range() and a list of values?

The main differences between the two boil down to the difference between greedy and lazy evaluation. With a list, each indexed object takes up some space in memory. Range, however, calcu...

Answered by Luke S. Python tutor
869 Views

What can I do with Python?

Systems programming e.g. searching for files, launching other programs etc (sometimes called shell tools)GUI’s -tkinterInternet Scripting – web scraping (getting information from websites so you can use i...

Answered by Joshua D. Python tutor
995 Views

Given a list of N numbers, use a single list comprehension to produce a new list that only contains those values that are: (a) even numbers, and (b) from elements in the original list that had even indices .

A simple solution to this problem would be as follows [x for x in list[::2] if x%2 == 0] For example, given the following list: list = [ 1 , 3 , 5 , 8 , 10 , 13 , 18 , 36 , 78 ] The list comprehension [x ...

Answered by Waseem A. Python tutor
1545 Views

how to compute the factorial of a number.

def factorial(n): fact = 1 for i in range(2,n+1): fact*=i; return factx=input("Enter a number :")print("The factorial of "+x+" is "+factorial(x))

Answered by Niveda R. Python tutor
513 Views

We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy