+ 1
Integers and strings
Why is the int sign ever needed? What is an example of when I would need that in a string? Could I not just make the numbers I wanted outside of the string.
5 odpowiedzi
+ 2
age = int(input("Enter your age: "))
+ 2
num1 = int(input())
num2 = int(input())
print(num1 + num2)
+ 2
for i in range(int(input("How many times will the loop be run? "))):
+ 1
If you want to multiplicate something, that can't be multiplicated with floats, such as lists, [6, 3, 1]*int(5.5) => [6, 3, 1]*5. You can also test whether a float is a whole number by testing int(x) == x