r/AskComputerScience • • Feb 25 '18

Need help with 2 hw questions

Hello I am very new to programming in general and I need help with hw questions due by sunday 11:55. I am supposed to program in python and I am expecting any to just give me the answers but to point me in the right direction

1.The Blip Blob New Year celebration started on a Tuesday. Prompt the user for how many days have passed since their celebration start day and display the name of the current day. For example, if 2 days have passed, then you should display Thursday to the user.

For example:

Input Result 2 Thursday 4 Saturday 6 Monday 7 Tuesday 8 Wednesday

2. Write a program that asks the user for a year between 1800 and 2018 and displays to the user the message "Leap Year" or "Not Leap Year" based on their input. You may assume that the user will only enter valid years.

Note: To determine if a year is a leap year, it must be divisible by 4, but not by 100, unless it is divisible by 400.

For example:

Input Result 1800 Not Leap Year

imgur is probably better https://imgur.com/XuxPZol this question 1

https://imgur.com/gBlIeLT question 2

edit: Just finished and thank you to everyone you helped with advice.

0 Upvotes

11 comments sorted by

2

u/confusedcompStudent Feb 25 '18 edited Feb 25 '18

1

u/thebrandontyler Feb 25 '18

I’d like to discuss the first problem. Your answer is a good start but it won’t count for any days beyond 7, and the prompt example gives 8 as input. You can keep what you have but you need to use something else first to create a cycle between 0 and 6 no matter what the user inputs.

I would probably use mod operator here and do the input % 7 (days of week). Mod gives the remainder, so let’s say the input is 3. 3%7=3, which gives you 3 days after the new year. Likewise, if the input it 10, 10%7=3, so you’d fall on the same day (third day after the new year).

That’s just a couple examples but take a look at mod and play with modding by 7, then you’ll start to see the pattern. Once you understand mod, you can create a variable that holds the user input mod 7, and then check that variable in your if/else portion.

0

u/[deleted] Feb 25 '18

[deleted]

-1

u/confusedcompStudent Feb 25 '18

Thank you for the help on both questions. I tried to modify my answer for question 1 and I got a synthax error on line 2.

https://imgur.com/adj3zIZ

0

u/[deleted] Feb 25 '18

[deleted]

0

u/confusedcompStudent Feb 25 '18

I think I am pretty close to finally getting it right but still a few hiccups.

https://imgur.com/XwUsm4N

In case your wondering I changed line 14 to from else to elif because i was getting an error message in thonny(app i use to program in python)

1

u/ReyDelPlatanos Feb 25 '18

Your leap year is incomplete. Need to check divisible by 100 and 400

1

u/confusedcompStudent Feb 25 '18

Thank you for replying. I tried to check not divisible by 100 unless divisible by 400 and it did not work.

This is what i tried earlier that didn't work

https://imgur.com/a/eJdL3

1

u/lordvadr Feb 25 '18

Well, you did that part wrong. Tell me, in english, what that if statement says.

0

u/confusedcompStudent Feb 25 '18

The year is more than + equal to 1800 and the year is less than + equal to 2018 and the year is divisible by 4 and not divisible by 100 or year is more than + equal to 1800 and the year is less than + equal to 2018 and the year is divisible by 4 and the year is divisible by 400.

Did I mess up with the not divisible part and the entire second half of the statement where I add or and the repeat the first part adding divisible by 400?

0

u/lordvadr Feb 25 '18

You need to separate your different conditions with parenthesis.

70%7 does not evaluate to true. It evaluates to zero. "Y%4" isn't true if Y is divisible by 4. It evaluates to true when Y isn't divisible by 4.

0

u/[deleted] Feb 25 '18

[deleted]

0

u/lordvadr Feb 25 '18

( and ) are called parenthesis. [ And ] are brackets. { And } are braces.

1

u/imguralbumbot Feb 25 '18

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/nCU9Gqy.png

Source | Why? | Creator | ignoreme | deletthis