Ascendant0
- 175
- 38
- TL;DR Summary
- I'm trying to put together code that simply accepts an input of any number, calculates the factorial of the number, and then prints out the resulting value
This is one of the things I've tried:
And this is the resulting error message I get: TypeError: can only concatenate str (not "int") to str
---
I copied that int(input() code right off a site that explained how to do it, set it up identical to how they did, yet it still stores the input as a str instead of an int (and as such, of course can't calculate the factorial). So for some reason, the int() command isn't working for the input?
I also tried changing it to an int after the input was received with these changes:
Again, I copied the suggestion on how to do it verbatim from a Python site, yet again, another error message: ValueError: invalid literal for int() with base 10: 'num'
There was a couple other things I tried that I can't even find again right now, but what is wrong here? I'm doing exactly what those sites are telling me to do to make the input an int, yet I continue getting some kind of error message or another, every single time???
Python:
import numpy as np
import matplotlib.pyplot as plt
import math
num = int(input("Enter an integer: "))
math.factorial(num)
print("The factorial of this value is " + num + ".")
And this is the resulting error message I get: TypeError: can only concatenate str (not "int") to str
---
I copied that int(input() code right off a site that explained how to do it, set it up identical to how they did, yet it still stores the input as a str instead of an int (and as such, of course can't calculate the factorial). So for some reason, the int() command isn't working for the input?
I also tried changing it to an int after the input was received with these changes:
Python:
num = int(input("Enter an integer: "))
string_value = "num"
integer_value = int(string_value)
math.factorial(integer_value)
print("The factorial of this value is " + integer_value + ".")
Again, I copied the suggestion on how to do it verbatim from a Python site, yet again, another error message: ValueError: invalid literal for int() with base 10: 'num'
There was a couple other things I tried that I can't even find again right now, but what is wrong here? I'm doing exactly what those sites are telling me to do to make the input an int, yet I continue getting some kind of error message or another, every single time???
Last edited by a moderator: