Python Challenge 7


#1

Hello i need help with challenge 7 the challenge asks us to write a code which depending on the amount of hours you spend watching tv replays with something.
*Ask the user how long on average they spend watching TV each day.
*If it is less than 2 hours, outputs ‘That shouldn’t rot your brain too much’; if it is less than 4 hours per day, outputs ‘Aren’t you getting square eyes?’; Otherwise outputs ‘Fresh air beats channel flicking’






#2

In Python, we take input using input. The syntax for this is as follows:

num = int(input("Give me a number: "))

This will display Give me a number: followed by an input of type int… So this expects the user to input a number. In addition to this, the result (the number the user puts in) will be stored in the num variable.

Once we have the number, in this case, the number of hours, we can compare that number to other numbers, and make a decision on what to do next as a result. To do this, we use conditional (if) statements. The syntax for this is as follows:

if(num>100): #is the input greater than 100?  If so, do this, if not, go to elif.
  print("Wow!  That's a big number!")
elif(num<0):  #is the input less than 0?  If so, do this, if not, go to else.
  print("That's a tiny number!")
else: #no other conditions are satisfied, so this must be the case.  Do this.
  print("That number is just right!")

This code combined will take in user input, and check if that value is either greater than 100, or less than 0, and print out a result based off the input. Here’s the code:

num = int(input("Give me a number: ")) #ask the user for a number

if(num>100): #is the input greater than 100?  If so, do this, if not, go to elif.
  print("Wow!  That's a big number!")
elif(num<0):  #is the input less than 0?  If so, do this, if not, go to else.
  print("That's a tiny number!")
else: #no other conditions are satisfied, so this must be the case.  Do this.
  print("That number is just right!")

Try adapting this code for your TV challenge.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.