int(intput()) inside a function does not work? [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
when I try to use the following function:
def ea():
x,y = int(input("enter age:")),input("enter name:")
if x > 0:
print(f"My name is {y} and I am {365*(x)} on earth")
else:
ea()
I get this error:
TypeError: int() takes 0 positional arguments but 1 was given.
I don't understand why as int(input()) works when not used in a function. Can anyone help?
Thanks in advance

def ea():
x, y = input("enter your name and age: ").split(" ")
y = int(y)
if y > 0:
print(f"My name is {x} and I am {365*(y)} on earth")
else:
ea()
Output :
>>> ea()
enter your name and age: thor 18
My name is thor and I am 6570 on earth

You Can Try This
def ea():
x = int(input("enter age:"))
y = input("enter name:")
if x > 0:
print(f"My name is {y} and I am {365*(x)} on earth")
else:
ea()

Related

TypeError: 'int' object is not callable (While working on google colaboratory) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
In python I got a "TypeError: 'int' object is not callable" during execution.
I had read other posts but I still can't figure out why it is like this.
# Python code to find if a number is
# prime or not using divmod()
# Given integer
n = int(input("Enter a number"))
x = n
# Initialising counter to 0
count = 0
while x != 0:
p, q = divmod(n, x)
x -= 1
if q == 0:
count += 1
if count > 2:
print(n, 'is Not Prime')
else:
print(n, 'is Prime')
And, please note that it doesn't gives any error by replacing:
n = int(input("Enter a number")) to n = int(input("Enter a number"))
I have also provided a screenshot regarding my problem 👇
image
Answer if anybody knows, Appreciation for any suggestions and comments.
Have you tried something like this?
z = input("Enter a number")
n = int(z)
x = n

i am trying to print out this simply equation, but it says float object is not callable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have been trying to print out this very simple equation but I cannot figure out why it will not print?
fc = float(input("first cycle is "))
fp = float(input("first percent is "))
sc = float(input("second cycle is "))
sp = float(input("second percent is "))
tc = float(input("third cycle is "))
tp = float(input("third percent is "))
mem = float(input("the memory is "))
first_part = (fc * fp + (sc(1-fp)))
print(first_part)
It gives me the error "TypeError: 'float' object is not callable"
The * multiplication operator cannot be omitted as it can in an algebraic equation. The interpreter thinks sc(1-fp) is a function call.
first_part = (fc * fp + (sc * (1-fp)))

How to fix a while syntax error in python? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm getting a syntax error on my 2nd while loop. Can't figure out why, any help appreciated :)
#intro
print("Welcome to my prime number detector.")
print("Provide an integer and I will determine if it is prime.")
#again loop
again = "Y"
while again == "Y":
num = (int(input("Enter an integer"))
#check for valid input
while num < 1:
num = (int(input("Enter an integer"))
#test for prime
for d in range(2,num):
if (num % d) == 0:
print(num,"is not prime.")
else:
print(num,"is prime.")
#ask again
again = intput("Do you want to play again? (Y/N)")
You are missing a closing parenthesis ) in the two of your following lines. The correct line of code is
num = (int(input("Enter an integer")))
Also, as sheepez mentioned below, your outer brackets are redundant. You can simply use
num = int(input("Enter an integer"))

NameError: name 'grade' is not defined [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to write a program that will number grade output when the user enters a letter grade. I am getting this error: NameError: name 'grade' is not defined. Can someone tell me what this error means and help me figure out how to fix it. I am new to programming so I am realy lost.
letterGrade = (input("Please enter a letter grade: "))
if grade >= A:
grade == "4.0"
elif grade < A:
grade < "4.0"
print(grade)
It looks like your if statements are checking for the variable grade, but your input is being assigned to letterGrade. You can fix this either by changing your first line to
grade = input("Please enter a letter grade: ")
or change every instance of grade to letterGrade.
Additionally, grade == "4.0" should probably be grade = "4.0"; x == y checks if x is equal to y, whereas x = y sets x equal to y.

Using random in an if statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to make a random number guessing game but I cant get the if statement to check if the users input is = to the random number
import random
realNumber = random.randint(1, 50)
print(realNumber)
myNumber = print(input("Guess the number from 1 to 50: "))
if int(myNumber) == realNumber:
print("You win")
else:
print("Nope guess again")
The unintended behavior of your program is due to this line:
myNumber = print(input("Guess the number from 1 to 50: "))
Here, you are trying to assign myNumber to the return value of the print statement (Which is None) and not the value obtained from the input() statement. To fix this, simply remove the print() around the input.
myNumber = input("Guess the number from 1 to 50: ")
Hope this helped!
You don't need the print statement around input.
import random
realNumber = random.randint(1, 50)
print(realNumber)
myNumber = input("Guess the number from 1 to 50: ")
if int(myNumber) == realNumber:
print("You win")
else:
print("Nope guess again")
Note that this code will not work if the user enters something besides an integer, because the int() call will not cast correctly

Categories