top of page
top

Python 2B - Inputting Numbers

noun-input-1454995-FFFFFF.png

Inputting Whole Numbers in Python

To enter whole numbers then you must use the int command.

 

 int stands for integer (a whole number) and is typed before input – don’t forget the double brackets at the end.

age = int(input("How old are you? "))
print("Have you really lived for, age , "years?")

=

How old are you? 99

Have you really lived for 99 years?

Inputting Numbers Task 1 (Zoo)

Type an input line (with int) to ask the user how many times they’ve been to the zoo.

Print a reply that uses the zoo variable (their answer). 

Example solution:

How many times have you been to the zoo? 3

You've been to the zoo 3 times? I love animals!

Inputting Decimal Numbers in Python

Using float instead of int allows a decimal number to be entered instead. 

 

Again, don’t forget the double brackets at the end.

miles = float(input("How far have you walked today? "))
print("You really walked for, miles , "miles? Wow!")

=

How far have you walked today? 5.6

You really walked for 5.6 miles? Wow!

Inputting Numbers Task 2 (Height)

Type an input line (with float) to ask the user their height in metres.

​

Print a reply that uses the height variable (their answer). 

Example solution:

What is your height in metres? 1.82

You are 1.82 metres tall? Wow!

bottom of page