0% found this document useful (0 votes)
4 views3 pages

01 - Python Basics

The document provides an introduction to basic Python programming concepts, including user input, variable assignment, and simple arithmetic operations. It explains how to prompt users for numbers and names, perform calculations, and display results. Additionally, it offers exercises for creating custom programs that involve user input and basic mathematical operations.

Uploaded by

jiannajaison
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

01 - Python Basics

The document provides an introduction to basic Python programming concepts, including user input, variable assignment, and simple arithmetic operations. It explains how to prompt users for numbers and names, perform calculations, and display results. Additionally, it offers exercises for creating custom programs that involve user input and basic mathematical operations.

Uploaded by

jiannajaison
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Basics

num = int(input(“Enter a number: ”))


This will ask the user to enter a number (it will only accept a whole number as the word “int” is used
at the beginning”) and save thei r answer in a variable called num.

print(num)
This will display the number they typed in

name = input(“Enter your name: ”)


This will ask the user to enter a text value and save their answer in a variable called name.

print(“Hello”, name)
This will display the word Hello and then their name.

answer = 5 + 6 print(answer)

This will work out the sum 5 + 6 and save the answer in a variable called answer. It will display the
answer on the screen.

num1 = int(input(“Enter a number: ”)) num2


= int(input(“Enter a number: ”)) answer =
num1 * num2 print(num1, “*”, num2,
“=”,answer)
This will ask the user to input two numbers (note the int at the start of the input statement and the
extra bracket at the end) called num1 and num2 and multiply them together saving the answer int
the variable called answer. It will then display the answer in an attractive format. The mathematical
symbols include + (addition), - (subtraction), * (multiplication) and / (division).

Reading Code
What will this program do?

This will ask the user to input 2 numbers for the apples and oranges. The numbers for both fruits
will then be added together, the answer being saved in the variable called fruit. Then it will display a
sentence on the screen which tells the user how many pieces of fruit they have, according to the
numbers they inputted.
Page 1
© Nichola Lacey 2018

Correcting Code
Why does this code not work?

They have forgotten to include the “int” before the input, meaning the program won’t know that
what it’s looking for is an integer, causing the addition to not work properly.

Create your own code


Make sure you save each
program with a sensible
name. To save time you
can reuse and adapt your old
programs to help you create new
programs.
1. Create a program that will ask the user to enter three numbers. Add all three numbers
together and divide by 3. Display the answer as “The average is [answer]”.
2. Ask for a number and multiply it by 10. Display the answer.

3. Ask the user to input their name and their age. Display the answer “Hi [name], you are [age]
years old.”

4. Ask the user to input two numbers. Take the second number away from the first number
and display the answer (even if this is a negative value).

Page 2
© Nichola Lacey 2018

You might also like