12 - Solving Mini Problems

 1. The following code needs to convert hours into minutes but there is an error. How would you fix it?
def convert_hours():
     #There is an error in the code below. Can you fix it? The code needs to convert hours into minutes
     hours=int(input("Enter no. of hours"))

  Change line 4 to: minutes = 60

  Change line 4 to: minutes=60*hours

  Change line 4 to: x * 60 minutes

  Change line 4 to: 60 x 60 x 60 = minutes

 2. Can you predict/describe what this function is doing?
def calculate():
     #Add two more tests scores for test4 and test5.
     #Adapt the code to find the average for the five test scores
     #find average of the three test scores
     print("The average mark is:",calculate)


  adding together three test scores and then finding a percentage

  finding the average of three test scores

  calculating the highest test score from three test scores that are input into the system

  adding together three test scores

 3. What would you add on line 8 to print a message and the number of remaining friends
def friends_list():
     #Add the facility to also add more friends after the remove function.
     #After removing x amount of friends (that the user specifies), print the remaining no. of friends again
     friends=int(input("Enter No. of Friends"))
     print("Thank you, you have,",friends,"friends")
     remove=int(input("Enter No. of Friends you wish to remove:"))
     #hat would you type on this line to print the remaining friends


  message("You have this many friends remaining") + remaining (print)

  print("You have this many friends remaining:",remaining)

  All of the above are valid options

  print("You have this many friends: remaining:")

 4. There may be something missing from this program that calculates the area of a circle, given its radius. What is it?
from math import pi
r = input ("Input the radius of the circle : ")
print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2))

  Line 2 should be: r = float(input ("Input the radius of the circle : "))

  Line 2 should be: r = input(radius("Input the radius of the circle:"))

  An additional line needs to be added to give the variable 'pi' a value of 3.14

  There is nothing missing. An input of 3.4 (for radius) would accurately give the area

 5. Which statement is most true in reference to the following code?
def findspeed():
  distance=int(input("Enter distance:"))
  time=int(input("Enter time: [for the sake of simplicity enter a whole number]>>"))
  print("The speed of the runner is:",speed)


  Speed is in metres per second or miles per hour etc, and this is not included

  Distance = 100, Time = 2,will give a result of 50.0

  All of the above are valid statements in reference to the given code

  The instructions to enter distance and time could be validated and clearer

 6. If the user enters 3, what will be ouput or printed to the screen?
def main():
  num=int(input("Enter a number between 5 and 50:"))
  while x<num+1:




  A list of numbers from 5 to 50


 7. What is missing from line 6?
def count_to_twenty():
  print("-----Counting to 20 using a while loop-------------")
  while x<21:
    #What is missing here?

  x = 20

  x = x + 1

  x + x - 1

  x > 1

 8. In the following program, if the user enters 5, it only prints: 0,1,2,3,4. How can it print all the way up to 5?
num=int(input("Enter integer:"))
for i in range(0,num):

  Change line 2 to: for i in range(0,5):

  All of the above are valid options

  Change line 2 to: for i in range(0,num+1):

  Change line 2 to: for i in range(5,0)

 9. What would the output be if the input here was: favourite number: 2; animal: dog, firstname: Joe
def main():
  number=input("Enter your favourite number:") #note you do not need to convert number here to an integer as you don't need to perform any calculations with it, but rather treat it like a string!
  animal=input("Enter your favourite animal")
  firstname=input("Enter your firstname")






 10. What will the output of the following code be?
def main():
   score=500 #initialise the score variable to 500
   while score<504:
       print("Whoo, you're in a loop") #print this while above condition true
       score=score+1 #the score keeps going up for each loop round

  "Whoo, you're in a loop" x 4 times

  "Whoo, you're in a loop" x 504 times

  "Whoo, you're in a loop" x 500 times

  "Whoo, you're in a loop" x 500 + 504 times