Classwork:
NOTE: Use python shell to confirm your answers for syntax questions
1. Write the code to assign the numerical value 54 to x.
2. Write the code to assign the string 54 to y.
3. What is the difference between questions 1 and 2?
4. What is the code to prompt the user for name and assign it to variable name?
5. Write a code snippet to compare two integer variables x and y. It should display the larger of the two.
6. What is the flowchart shape for a condition?
7. How many arrows point to any one flowchart shape?
8. How many arrows leave a rectangular flowchart shape?
9. Up to how many arrows leave a conditional flowchart shape? Explain your answer.
10. What is the instruction to display a numerical variable age and a string ” years old”?
11. What is the code to prompt the user for a real number amount and assign it to variable amount?
12. Write the python instruction to find the average of the integer variables x1, x2, and x3.
13. Write the python instruction to find the standard deviation of the integer variables x1, x2, and x3. What do you need to import?
14. What is the result of executing the following python instruction? Explain how python solves the expression.
x = 5 – 2 * 10 + 5
15. How should you write the statement to get 35?
16. What is a boolean variable?
17. Write an instruction to assign the value of pi to variable myPi with relative high precision.
18. Write two different statements to display two variables, one is a integer and the other a string.
19. Given that number is a 4-digit integer, what is it displayed after execution?
x = number % 10 y = number // 10 % 10 z = number // 100 % 10 print (x, " ", y , " ", z)
- Can you guess the next one?
- What does this code snippet do?
x = int(input("Enter first number ")) y = int(input("Enter second number ")) if x < y: t = x x = y y = t if x % y == 0: print("True") else: print("False")
Homework:
1. Write a python program, YI_TimesTables.py to display a two dimensional table of the product of two numbers from 1 to 10. The output should look like this:
1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 >>>