Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help making my program add
#1
Wall

Hello everyone, my name is Zack and I’m new to python I’ve started writing very basic programs to get my head around various python functions but now I’m stepping it up a level by trying to write a slightly more complex program, but i have quickly gotten stuck... here is what the program is supposed to do...

It asks the user “how many hours of homework have you done today” and then uses an if statement to determine what the output should be, that works fine but the problem is I want to have the program ask this question for all seven days of the week from Monday to Sunday and then add up the total and then go to the if statement depending on whether or not the total amounts to the required 3 hours per day, I’ve tried just about everything in my admittedly very limited tool box to make the program do this and it just won’t work, it just prints the second if statement every time. I know it’s probably something simple but I've been working on it for nearly two weeks and can’t figure it out.
Does anyone have any suggestions on how to make the program do what I want or anything I might be missing?
I've included the code so you can see how I've done it and hopefully can tell me what I've done wrong.

Any and all help is greatly appreciated 

Thanks 

Zack 


my code here
print("How many hours of HomeWork did you do today? (Monday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Tuesday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Wednesday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Thursday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Friday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Saturday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Sunday):")
input=int(raw_input())
if input >=21:
print("Well done, keep up the good work!")
if input <21:
print ("Not good enough, you must try harder!!")
Reply
#2
First, code tags make things easier to read.  Try to use them in the future :)

Next, let's look at this snippet:
 print("How many hours of HomeWork did you do today? (Monday):")
input=int(raw_input())
print("How many hours of HomeWork did you do today? (Tuesday):")
input=int(raw_input()) 
You overwrite whatever value input had, and replace it with the new value.  If you want to add them up as you go, instead of input = #etc, use input += #etc to add them to whatever input was before.

OR, you could use a list to keep track of all values, then add them up at the end:
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
hours_worked = []

for day in days:
    hours = int(raw_input("How many hours did you work today? ({0})".format(day)))
    hours_worked.append(hours)

# check out all 5 numbers
print(hours_worked)

# the total hours worked:
print(sum(hours_worked))
Reply
#3
Thanks so much ill give it a try. What are code tags ?

Zack
Reply
#4
https://python-forum.io/misc.php?action=help&hid=25
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Some help with my first python class and importing ....im making a lidar program jttolleson 7 1,199 Jul-28-2023, 08:34 AM
Last Post: jttolleson
Smile Help making number analysis program Dainer 2 1,753 Jun-24-2021, 09:55 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020