Create a new program squared_parameter.py. Copy the following code into it and complete the function output, which uses the parameter x to print the value of x and its square:
def output(x):
print('Number', ...)
print('Squared equals', ............)
output(1)
output(2)
output(3)
The program should print:
Number 1
Squared equals 1
Number 2
Squared equals 4
Number 3
Squared equals 9
Create a new program circle_parameter.py. Copy the following code into it and complete it so that it draws circles with center at point 200, 150 and radius r, which will be the parameter of the function:
import tkinter
canvas = tkinter.Canvas()
canvas.pack()
def circle(r):
canvas.create_oval(......., ......., ......., .......)
circle(10)
circle(100)
circle(50)
Create a new program square_parameter.py and define a function square with parameter a, which specifies the side length of a square. The function should work so that it draws a square only for positive values of a, and for negative values it prints the message “impossible” in the center of the canvas. The upper-left corner of the drawn square will have coordinates [10, 10]. Test the program.
Create a new program quiz.py, which will work as a simple addition quiz. At the start, the computer generates two random numbers from 1 to 10, prints them, and we must answer by calling the function check() from the command line. The computer then checks whether our answer was correct:
=========== RESTART ===========
How much 10 + 7 ?
>>> check(5)
Incorrect, it should be 17
>>>
=========== RESTART ===========
How much is 4 + 9 ?
>>> check(13)
Correct!
>>>
We want to explore how often the number 6 appears when rolling a die multiple times. Create a program luck.py with a function luck that has parameter n, which simulates n rolls of a standard die. The function generates a random number 1–6 n times, and whenever a six appears, it increases a counter by 1. At the end, the function prints a message in following format:
The probability of winning with 10 rolls: 0.2
Use the program to print the probability of winning for 10, 100, 1000, 10000, 100000 rolls.