TORONTO KIDS COMPUTER CLUB | Saturday 16:30 Python Practice – 22.04.30.
20597
post-template-default,single,single-post,postid-20597,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Saturday 16:30 Python Practice – 22.04.30.

02 May Saturday 16:30 Python Practice – 22.04.30.

You can do Question 1~ 3 in Python IDLE Shell:

Question 1.

Use float() to create a number from a string like ‘12.34’. Make sure the result is really a number!


Question 2.

Try using int() to create an integer from a decimal number like 56.78. Did the answer get rounded up or down?


Question 3.

Try using int() to create an integer from a string. Make sure the result is really an integer!


Please create new files and write program for following questions (Do NOT write in the IDLE Shell, you can tell the difference by seeing >>> in front of the IDLE Shell but not in the new file ), detailed instructions as below:

  • Open Python IDLE
  • In Menu Bar, Click “File” => “New File” (important!!!)
  • Write your program in the new file
  • After finishing writing the program, click “Run”=>”Run Module” in menu bar or just press “F5”
  • Python will ask you save the file before run the program
  • Check your code and fix the errors.

Question 4.

Write a program that asks for your first name, then asks for your last name, and then prints a message with your first and last names in it.

Sample Input:
What is your first name? Kevin
What is your Last name? Zhu

Sample Output: 
(it means if user enters the above answer as Kevin for first name and Zhu for last name, 
then the following information will be printed out)
Your name is Kevin Zhu

Hint:
Use input() to ask question and get answer, for example:

firstName = input("What is your first name?")

The string answer as value will be assigned to variable firstName.


Question 5.

Write a program that asks for the dimensions (length and width) of a rectangular room, and then calculates and displays the total amount(area) of carpet needed to cover the room.

Sample Input:
Length: 5.2
Width: 2.4

Sample Output: 
Carpet need: 12.48

Hint:
Use input() to ask question and get answer, however, you can only get string data type of answer. In order to get decimal number as dimensions, you need to use float(input(…..)) which will convert from string answer into a decimal number, for example:

w = float(input('Width: '))
No Comments

Sorry, the comment form is closed at this time.