Help with converting string to integer

Hi all,

I’m making a simple project to get to grips with using the modulo operator and trying to figure out why my code can’t convert the input string into the corresponding integer: Any help would be truly awesome. Also if my code doesn’t make sense for whatever reason i’d be happy to know why so that I can try and improve. Thank you.

Oh, and this is my traceback error:
“line 24, in
new_day = current_day + num_of_days_in_the_future % 7
TypeError: not all arguments converted during string formatting”

current_day = str.upper(input("What Day Is It Today?:"))
num_of_days_in_the_future = (input("How many days into the future do you want to look?"))

    if current_day == "MONDAY":
        current_day = 0
    if current_day == "TUESDAY":
        current_day = 1
    if current_day == "WEDNESDAY":
        current_day = 2
    if current_day == "THURSDAY":
        current_day = 3
    if current_day == "FRIDAY":
        current_day = 4
    if current_day == "SATURDAY":
        current_day = 5
    if current_day == "SUNDAY":
        current_day = 6

new_day = current_day + num_of_days_in_the_future % 7

    if new_day == 0:
        print("Monday")
    if new_day == 1:
        print("Tuesday")
    if new_day == 2:
        print("Wednesday")
    if new_day == 3:
        print("Thursday")
    if new_day == 4:
        print("Friday")
    if new_day == 5:
        print("Saturday")
    if new_day == 6:
        print("Sunday")

print("\nThe projected day will be: ", new_day)

print("Thank you for using this program")

please post your code not a screenshot

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Done, sorry about that.

what have you given as input to the prompts? so it is possible to replicate as best your error


but I think it’s here:

from here:

as input gives back a string you need to convert to integer before being able to use it in maths oeprations

2 Likes

take a look at the second part of my last post

1 Like

I think ieahleen gave a good hint, if you look into that first, there is no need to make it more complicated :wink:
the error states that integers cannot be added to strings, so you might want to find where that is happening right now and do the conversion.

You could try to use print(type())

1 Like

Oh wow, got it. Thankyou soo much! :slight_smile:

# Modulo practice , "Looping" numbers to create projected outcomes

current_day = str.upper(input("What Day Is It Today?:"))

if current_day == "MONDAY":
    current_day = 0
if current_day == "TUESDAY":
    current_day = 1
if current_day == "WEDNESDAY":
    current_day = 2
if current_day == "THURSDAY":
    current_day = 3
if current_day == "FRIDAY":
    current_day = 4
if current_day == "SATURDAY":
    current_day = 5
if current_day == "SUNDAY":
    current_day = 6

num_of_days_in_the_future = int(input("How many days into the future do you want to look?"))

new_day = current_day + num_of_days_in_the_future % 7

if new_day == 0:
    print("\nThe projected day will be: Monday")
if new_day == 1:
    print("\nThe projected day will be: Tuesday")
if new_day == 2:
    print("\nThe projected day will be: Wednesday")
if new_day == 3:
    print("\nThe projected day will be: Thursday")
if new_day == 4:
    print("\nThe projected day will be: Friday")
if new_day == 5:
    print("\nThe projected day will be: Saturday")
if new_day == 6:
    print("\nThe projected day will be: Sunday")

print("\nThank you for using this program")