Day 011 - Project 11 : How many seconds are in a year?

If you have any questions, comments or issues with this project please post them here!

How many seconds in a year :scream_cat: !!

https://replit.com/@JackAdem/Day-011-Project-11-How-many-seconds-are-in-a-year?v=1

Day 11 of #Replit100DaysOfCode #100DaysOfCode.

1 Like

This is mostly a note for myself to keep me going for 100 Days Of Code but where others can also read it if they would like:
Day 11- Just finished day 11 of 100 for #100-days-of-code! I am still enjoying doing this and I can’t wait to get into even more fun stuff down the road. I can’t wait to be on that day 100 where I can look back at where I started and see how much better I have been doing.

Replit- https://replit.com/@Chandler0Bing/100-Days-Of-Code-Day-11

2 Likes

Looks amazing! My only advice, try to find a way to simplify the code.

1 Like

Normally I leave the spelling/grammar corrections to @QwertyQwerty88 but this one bothers me. Please change “leep” to “leap” in your code. That’s how it’s spelled. Also you might want to change it to “28-30 days in a Month”.
image
I like the double spacing, which makes the output easier to read. The only real problem with your code is that it generates the wrong number. I used a calculator (not Python) to determine this and 60 seconds per minute * 60 minutes per hour * 24 hours per day * 365 days per year = 31536000 seconds per year. I think the problem is using the months (which have variable day numbers) in your calculations. You could do math for each month if you would like. That would be cool to see how many seconds are in each month.

1 Like

print(“Seconds in a year”)

seconds_In_Years = int(input("Tell me the year, please: "))

year = 365
hours_a_day = 24
minutes_hour = 60
seconds_minute = 60

seconds_In_Years = year * hours_a_day * minutes_hour * seconds_minute

print(seconds_In_Years)

leap_Year = 366

leap_Year = leap_Year * hours_a_day * minutes_hour * seconds_minute

if seconds_In_Years == 365:
print(“seconds in a leap year”, leap_Year)
else:
print(“There are”, seconds_In_Years, “seconds in a year”)

ok so i know i’m missing a part here, bc everything is coming back the same, as if the year is not a leap year. I need to tell the program, what a leap year is, so i just can’t figure out how to incorporate the leap year code into this code…and need some help pls.

Clue: a year is a leap year if it is a multiple of 4. x % y returns the remainder of xĂ·y.

3 Likes

i got it with some help, and it was my logic in the if statement at the end as i had thought. so, here’s the updated version, which works now :slight_smile: thanks again for the help as well

import calendar

year_Input = int(input(“Enter Year”))
isLeapYear = calendar.isleap(year_Input)

year = 365
leap_Year = 366
hours_a_day = 24
minutes_hour = 60
seconds_minute = 60

seconds_In_Years = year * hours_a_day * minutes_hour * seconds_minute
seconds_in_Leap_Years = leap_Year * hours_a_day * minutes_hour * seconds_minute

if isLeapYear:
print("seconds in a leap year are ", seconds_in_Leap_Years)
else:
print("seconds in year ", seconds_In_Years)

also, ps - instead of going that route, i went and did an import of calendar and went that route with the leap year logic

2 Likes

How many seconds in a year problem, Day11

The code is not outputting an integer and also when answering the input statement even if the answer is either yes or no it always outputs the else statement

Hey @WarOfKratos welcome to the forums!

I see an issue with your code, when printing the statement out you use strings instead of the variable (the quotes make a value a string), you can change it to this instead → print(OneYear + OneYear2 + OneYear4) (no quotes means it isn’t a string (unless the variable is a string to start with) you can also put whatever values you want). Instead of using if input == “yes” I would recommend using the variable that you declared for the input → if Leap_Year == “yes”. Also when typing out your code make sure your lines are on the same indent (it matters with Python), line 8 and 10 are different indents but they should be the same. I hope this helps!

1 Like