This installment of the Python Crash Course walks through 7 variable practice problems!
Questions Covered
1. Ask the user for a number. Multiply the number by 10 and print it back out to the user.
2. Ask the user for two numbers. Divide the first number by the second number and print out the result.
3. Ask the user for their name, age, and favorite food. Print out 1 message to the user with all of this information.
4. Ask the user for their year of birth. Calculate how old they are based on todays year. Return this result back out to the user
5. Ask the user for three numbers and make a list out of these numbers. Print out the resulting list
6. Access the first and last element in a list and print it out to the screen. Make sure to test your code on lists of various sizes! Hint: len(listname) returns the number of elements in the list.
7. Create a 10 element long list. Ask the user for a number between 1 and 10 and another number. Insert the second number into your created list at the position of the first number.
Example:
Input: 3, 50
startinglist = [1,2,3,4,5,8,6,9,10]
Output: [1,2,3,50,5,8,6,9,10]
コメント