# Help with converting string to integer

**URL:** <https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [March 9, 2021, 9:48am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264 "2021-03-09T09:48:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pegasus](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pegasus/32/208945_2.png) [@Pegasus](https://forum.freecodecamp.org/u/Pegasus)\
**Post date:** [March 9, 2021, 9:48am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/1 "2021-03-09T09:48:11Z")

</div>

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”

```auto
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")

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 9, 2021, 9:49am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/2 "2021-03-09T09:49:30Z")

</div>

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.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![Pegasus](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pegasus/32/208945_2.png) [@Pegasus](https://forum.freecodecamp.org/u/Pegasus)\
**Post date:** [March 9, 2021, 9:55am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/3 "2021-03-09T09:55:23Z")

</div>

Done, sorry about that.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 9, 2021, 10:27am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/4 "2021-03-09T10:27:04Z")

</div>

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:

> [@Pegasus](#):
>
> ```auto
> new_day = current_day + num_of_days_in_the_future % 7
> 
> ```

from here:

> [@Pegasus](#):
>
> `num_of_days_in_the_future = (input("How many days into the future do you want to look?"))`

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 9, 2021, 10:56am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/6 "2021-03-09T10:56:02Z")

</div>

take a look at the second part of my last post

---

<div class="post-metadata">

**Author:** ![Brain150](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/brain150/32/134575_2.png) [@Brain150](https://forum.freecodecamp.org/u/Brain150)\
**Post date:** [March 9, 2021, 10:58am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/7 "2021-03-09T10:58:25Z")

</div>

I think ieahleen gave a good hint, if you look into that first, there is no need to make it more complicated 😉  
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())`

---

<div class="post-metadata">

**Author:** ![Pegasus](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pegasus/32/208945_2.png) [@Pegasus](https://forum.freecodecamp.org/u/Pegasus)\
**Post date:** [March 9, 2021, 11:05am UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/8 "2021-03-09T11:05:27Z")

</div>

Oh wow, got it. Thankyou soo much! 🙂

```auto
# 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")

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 7, 2021, 11:06pm UTC](https://forum.freecodecamp.org/t/help-with-converting-string-to-integer/450264/9 "2021-09-07T23:06:24Z")

</div>

Closed on September 7, 2021, 11:06pm UTC

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