L2 Python - Arithmetic Flashcards
1
Q
Data Types:
A
- String holds alphanumeric data as text
- Integer holds whole number
- Float holds numbers with a decimal point
- Boolean holds either ‘True’ or ‘False’
2
Q
Maths Symbols in Python
A
- Multiply = *
- Power = **
- Divide = /
- Add = +
- Subtract = -
- Square root = math.sqrt
3
Q
Casting:
A
- Python automatically assigns a data type to a variable
- You can override this using Casting
4
Q
Concatenation:
A
Animal
- Concatenating means “to join together”
- The plus symbol (+) joins two strings together
- Don’t forget to add extra spaces to make your output look nice
- Using the comma (,) displays the variable with spaces around it
Animal = input(“Enter the name of an animal:”)
Description = input(“How would you describe a “ + animal + “ ? “)
Print (“A” ,animal, “is” ,description)
Print (“You will find it under “ ,animal, “ inthe dictionary”)
5
Q
Program to add two numbers together:
A
num1=int(input(“Enter first number to add”))
num2=int(input(“Enter second number to add”))
sum = num1+num2
multiply = num1*num2
print (“The total is “ + str(sum))
6
Q
Program to find hypotenuse of a triangle:
A
import math num1=float(input("Enter the first short side ")) num2=float(input("Enter the second short side”)) num3=num1**2 num4=num2**2 num5=num3+num4 num6=math.sqrt(num5) print ("Answer =" , num6)
7
Q
Program to find shorter side of a triangle:
A
import math num1=float(input("Enter Hypotenuse ")) num2=float(input("Enter known short side ")) num3=num1**2 num4=num2**2 num5=num3-num4 num6=math.sqrt(num5) print ("Answer =" , num6)