External Exam Download Resources Web Applications Games Recycle Bin

Data Types

adding.py

myLuckyNumber = 5
print(myLuckyNumber + 5)


joining.py

myLuckyNumber = 5
newNumber = myLuckyNumber + 5
print("My new lucky number is: " + str(newNumber))
print("Maybe this would be easier:", newNumber)


number input.py

myLuckyNumber = int(input("What is your lucky number? "))
newNumber = myLuckyNumber + 5
print("Your new lucky number is: " + str(newNumber))


variables.py

container_A = 3
container_B = 4
container_C = "5"

print(container_A * container_B) #12
print(container_A * container_C) #"555"
print(container_A + container_B) #7

#however this won't work:
print(container_A + container_C) #... error:

#you can ADD (+) integers with integers
#you can JOIN (+) strings with strings

#but you CANNOT add or join strings with integers (or integers with strings)...
#...WITHOUT conversion first. The following will work:

print(str(container_A) + container_C) #"35"
print(container_A + int(container_C)) #8


data types.py

myNumber = int(input("Enter an integer to square: "))
result = myNumber * myNumber
print("Your number squared is: " + str(result))

anotherNumber = float(input("Enter a decimal number:"))
anotherResult = anotherNumber / 10
print("Ten percent of your number is roughly " + str(anotherResult))


  1. Write a program that adds 1 plus 1 together and outputs the answer

  2. Input a number from the user, then return the number inputted from the user multiplyed by 10.

  3. Input a number from the user, then return the number inputted from the user multiplyed by itself. For example, if the user inputs 5, your program would return 25.

  4. Create a program that inputs my postcode as a string. Create a variable NEIGHBOUR and use it to store (using the int function) the inputted postcode minus one. Output "The postcode in the next suburb is NEIGHBOUR" (where NEIGHBOUR is the value of the neighbouring postcode.)

  5. Extension:


  6. Write a program that calculates the area of a circle from a given radius input

  7. Ask a user to input their age. Print out their year of birth by using the formula year of birth = current year - age (in years)

  8. Write a program that inputs two whole numbers into two variables (call the variables num1 and num2), then outputs the sum, product and difference of those two numbers.

  9. Write a program that inputs a whole number, and prints an arrow like this: ---> but with the length of the arrow (or number of dashes in the arrow) equal to the whole number inputted