Using the print command, print the values of the following expressions one below another:
1*1
11*11
111*111
1111*1111
...
111111111*111111111.
Create a program called age.py that contains the following code and run it:
age = 16
print('Mám', age, 'rokov.')
Add another command to the end of the age.py program that prints the following message:
Budúci rok budem mať 17 rokov.
Create a program called wallet.py. Assign how many euros you have to the variable money. Assign the price of the purchase to the variable payment. Use the variables and print:
Mám ... eur.
Platím ... eur.
Zostane mi ... eur.
The school playground is 50 metres wide and 80 metres long. During physical education, you will run around its perimeter. Create a program called playground.py that calculates and prints how many metres you will run after 7 laps. At the beginning of the program, assign the value 50 to the variable width, the value 80 to the variable lenght, and the value 7 to the variable lap_count. Using these variables, print:
Šírka ihriska je 50 metrov, dĺžka je 80 metrov.
Jeden okruh okolo ihriska je 260 metrov.
Po 7 kolách prebehneš 1820 metrov.
Now suppose that the school playground is 45 metres wide and 70 metres long. Assign these values to the corresponding variables. Does the program print the correct values on the second and third lines? If not, correct the program.
An online music store offers a 20% discount. You want to buy an album whose original price was €17.95. Write a program called sale.py that calculates how much you will pay. Use the variables original_price, discount, and discounted_price in the program and use them to calculate and print:
Cena albumu je 17.95 Eur
Zľava činí 20 percent
Zaplatíš 14.36 korun
What final price will the program print for an album whose original price was €35.24 with a 30% discount?
What discount amount will the program print for an album whose original price was €26.69 and whose price after the discount was €20.02?
Write a program called discussion.py that evaluates the discussion:
Počet príspevkov od Aleny: 3
Počet príspevkov od Petra: 6
Počet príspevkov od Martina: 45
Create the program so that at the beginning, the variables pocet1, pocet2, and pocet3 are assigned the number of Alena’s posts, the number of Peter’s replies to each of them, and the number of Martin’s comments on each post.
According to your program, how many comments would Martin have to write if Alena wrote 4 posts? The number of Peter’s and Martin’s replies/comments and the method of calculation remain unchanged.
Let’s learn how to work with a graphics interface in the Python programming language.
Create a new program called canvas.py with the following contents:
import tkinter
canvas = tkinter.Canvas()
canvas.pack()
Run the program – a new window will appear on the screen.
Find out whether we can move the window and change its size. Finally, close the new window.
In VS Code, you may need to add one more line to the code: tkinter.mainloop()
Add a new command to your canvas.py program and run the program again:
import tkinter
canvas = tkinter.Canvas()
canvas.pack()
canvas.create_rectangle(50, 70, 220, 150)
There are 4 numbers in the parentheses of the canvas.create_rectangle( , , , ) command. Try changing them one by one in the canvas.py program. Run the program each time to see what it draws:
a) canvas.create_rectangle(0, 0, 220, 150)
b) canvas.create_rectangle(0, 0, 50, 50)
c) canvas.create_rectangle(0, 0, 250, 50)
d) canvas.create_rectangle(20, 10, 250, 50)
e) canvas.create_rectangle(20, 10, 50, 250)
Change your canvas.py program so that it draws a rectangle whose opposite vertices have the coordinates [50, 30] and [300, 200].
a) Without using a computer, calculate the width and height of the rectangle from the previous task. b) Verify your calculation using a screenshot and any graphics editor.