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

Untitled Yyyyy

The document contains several coding exercises focused on basic programming concepts such as calculating averages, counting items based on input codes, tallying vehicle types, calculating speeds, and determining travel fees. Each question includes a loop to gather user input and perform calculations or condition checks. The code snippets demonstrate the use of variables, conditionals, and loops in a programming context.

Uploaded by

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

Untitled Yyyyy

The document contains several coding exercises focused on basic programming concepts such as calculating averages, counting items based on input codes, tallying vehicle types, calculating speeds, and determining travel fees. Each question includes a loop to gather user input and perform calculations or condition checks. The code snippets demonstrate the use of variables, conditionals, and loops in a programming context.

Uploaded by

Tadiwa Mutama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 6

average_temp=(0.0)
average_Shours=(0.0)
for i in range (365):
temparature=float(input("Temaprature="))
sunshine_hours=float(input("Sunshine Hours="))
average_temp=average_temp+temparature
average_Shours=average_Shours+sunshine_hours
av_temp=average_temp/2
av_SH=average_Shours/2
print ("Average temparature is", av_temp, "degrees")
print ("Average sunshine hours are", av_SH, "hours")

Question 7
cards = 0
sweets = 0
stationery = 0
toys = 0

for i in range(5):
code = input("Enter code: ")
try:
first_digit = int(code[0])
if first_digit == 0:
cards += 1
print("Number of cards:", cards)
elif first_digit == 1:
sweets += 1
print("Number of sweets:", sweets)
elif first_digit == 2:
stationery += 1
print("Number of stationery:", stationery)
elif first_digit == 3:
toys += 1
print("Number of toys:", toys)
else:
print("Invalid code: First digit must be 0-3.")
except (ValueError, IndexError):
print("Invalid input. Please enter a valid code.")

print("Total Cards:", cards)


print("Total Sweets:", sweets)
print("Total Stationery:", stationery)
print("Total Toys:", toys)

Question 8
cars=int(0)
buses=int(0)
lorries=int(0)
other=int(0)
vehicles=int(0)
for i in range (10000):
vehicles=str(input("Vehicle type"))
if vehicles=="cars":
cars += 1
print (cars)
if vehicles=="lorries":
lorries += 1
print (lorries)
if vehicles=="buses":
buses += 1
print (buses)
if vehicles=="other":
other += 1
print (other)
Question 9
start_time=0
end_time=0
total_time=0
highest_speed=float()
for i in range (3):
start_time=int(input("Enter the start time"))
end_time=int(input("Enter the end time"))
total_time=(end_time-start_time)/60
speed=100/(total_time)
print (speed,"km/hr")
if speed>=100:
print(speed,"You are going too fast buddy")
if speed>highest_speed:
print("Highest speed is", speed,"km/hr")
if start_time != 0:
print("Invalid start time")

Question 10
fee=float(0)
number_of_passengers=int(input("How many are traveling"))
start_point=int(input("Please enter the start point"))
end_point=int(input("Please enter the end point"))
if start_point<end_point:
fee=(end_point-start_point)*2
print ("The total fee of travel is", "$",fee)
if number_of_passengers == 3:
discount = 0.1*fee
fee=fee-discount
print("Since you are traveling in 3s we have to decided to give you a 10%
discount which will make your discount", discount)
print("Fee after discount $", fee)
if end_point<start_point:
fee=(start_point-end_point)*2
print ("The total fee of travel is", "$",fee)

You might also like