Uploaded by Xuân Huy Nguyễn

Python exercises

advertisement
SELF-PRACTICE EXERCISES
1. These lines print the same thing, both print 6 after running the code.
The first code prints 6 in integer form
Another prints 6 in the string form
2. These lines prints different thing
The first code print 7 on the screen ( x is assigned to 7)
Another prints the letter x on the screen
3. 1.8 . 10308
4. 2.2 . 10−308
5. The system will announce that this variable is not defined
6. The right code line would be x = 10 not 10 = x
7. Yes, it could be changed. It can simply assigned a different value by another
code line
Ex: x = 10
x=x+1
print(x) => The screen will show 11
8. Yes, by using comma
Ex: a, b = 1, 2
Or a = b = 1
9. Legal: a, e, f, i, j, k, l, m, o, p, q, r, t
Illegal: b, c, d, g, h, n, s, u
10.
We can add _ in the variable name
Ex: for_ is a variable while “for” is a reserved word
11.
2.5𝑒 − 5
12.
4.5𝑒 − 26
13.
5.7𝑒 + 37
14.
No
15.
It depends on the way you use it.
Ex: string str= “i"; here i is a string literal
int i=8; here i is the variable
16.
If we write Print(‘n’), the screen will appear the letter n
If we run the code print(‘ \n’), the screen will show nothing because it would
show a line break.
17.
18.
print("A\nB\nC\nD\nE\nF")
import winsound
frequency = 1000
duration = 1200
winsound.Beep(frequency, duration)
Download