Python Homework
Python Homework
Introduction to Python
True as the variable name is not the same as the other variable name.
4. This code would print the letter “h”
planet = "Earth"
print(planet[5])
False because the first character in python is 0 so it would need to be
print(planet[4])
5. This code will print out “15”
number = "5" + "10"
print(number)
False, the output will be 510 as this code puts 5 in front of the ten so it is 510
6. Write a program which will allow a user to enter their first name, and their
favourite food. The program will then print out the sentence which includes the
data they input, all in uppercase. For example:
1
Homework 1 Strings and variables
Introduction to Python
“HENRY LIKES STRAWBERRIES”
Then print out the number of characters in the sentence (including
spaces), e.g.:
“The sentence contains 24 characters”[5]
In your program code, you may need to make use of one or more of the
following functions: len(), upper(), str()
For example:
notice = "No Entry"
numletters = len(notice) #puts 5 in numletters
newNotice = notice.upper() #puts "NO ENTRY" in newNotice
number = 12345
numberAsString = str(number) #puts "12345" in number as string
My Answer
print("Please enter your first name ")
first_name = input()
print("Please enter your favourite food ")
food = input()
first_name = first_name.upper()
food = food.upper()
print(first_name + " LIKES " + food)
numchara = len(first_name + " LIKES " + food)
print("The sentence contains " + numchara + " characters")