Invalid syntax error [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 6 years ago.
Improve this question
I'm trying to write a program that calculates BMI by asking what one's weight (in kilograms) and height (in meters) is. Why am I getting an invalid syntax error here?
units = input("What units would you like to use? Enter I for Imperial or M for Metric")
weight = input(int("what's your weight?")
height = input(int("what's your height?")
enter image description here

You've picked the wrong order. You should be having int(input()) not the input(int())
And also you have less ) than you should be. Check that for every opening bracket there is a closing one

You have the wrong order of int and input and did forget the closing parenthesis:
units = input("What units would you like to use? Enter I for Imperial or M
for Metric")
weight = int(input("what's your weight?"))
height = int(input("what's your height?"))

Avoid using input() and use raw_input() instead. You also put int() in the wrong place.
Your code should look something like this:
units = raw_input('What units would you like to use?....')
weight = int(raw_input("what's your weight?"))
height = int(raw_input("what's your height?"))

Related

Reading ints in input in a Python program [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 3 months ago.
Improve this question
I have to take input from the user then the operator has to print what number is before the input and after the input like:
input= 3
has to print 2 and 4
I used range, did I do it wrong? I am just a beginner in Python.
number=int(input)
for num in range(number ,+ 1, -1):
print(num)
You first need to use input() to let the user register a number.
Then, simply print the number with number - 1 and number + 1.
number = int(input("What is your number? "))
print(f"{number - 1} {number + 1}")
Outputs to:
What is your number? 3
2 4
you don't need range do this task
num = int(input())
print(num-1, num+1)
Other answers which say that you don't require a loop are perfectly fine, however I want to add a little suggestion in case you need to print more than just the number before and after. Maybe (as your first implementation suggests) you want to print the 5 numbers before and after. In this case you can do:
R = 5 #range
N = int(input("Enter your number. "))
numbers = [ i for i in range(N-R,N+R+1) if i != N]
print(numbers)

Python ignores "if" statement, a possible scope problem? [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'm trying to write a weight converter which splits the given input and act accordingly however if statement is completely ignored. So far my search revealed that it might be a scope problem but I'm pretty green so couldn't apply any solutions to my specific code.
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit
Try this:
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower() == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit

Why this Syntax Error on Python 3.8 for Mac [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
Check out the screenshot and help this newb with why i'm getting this syntax error with the for loop even though im following the right syntax.
The code :
elif choice == 'AVERAGE':
import statistics
lst = []
n = int(input('Enter number of values to calculate mean of: ')
for i in range(0,n):
ele=int(input())
lst.append(ele)
The Error : Invalid Syntax for the ':' after 'range(0,n)'
You are spacing the items inside the for loop with double Tab, the indentation should be either 4 spaces or a single tab.
And you are missing a parenthesis closing in the n input line
See the modified code below.
elif choice == 'AVERAGE':
import statistics
lst = []
n = int(input('Enter number of values to calculate mean of: '))
for i in range(0,n):
ele=int(input())
lst.append(ele)

Can't convert 'tuple' object to str implicitly [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 8 years ago.
Improve this question
a=int(input("please input number of players "))
while (a < 2):
a=int(input("please input at least two players "))
if (a==2):
p1=input("please enter name for player 1 ")
p2=input("please enter name for player 2 ")
x=float(input("please enter initiative for "+(p1)))
y=float(input("please enter initiative for "+(p2)))
x=x,p1
y=y,p2
if (x > y):
lowest=y
highest=x
elif(y > x):
lowest=x
highest=y
print(lowest)
steps=int(input("Please enter number of steps for "+(lowest)+" action" ))
i have tried everything i can think of and it needs to do this but i can't figure out how to make it work
That's exactly what the message say: in the last line, in the subexpression
"Please enter number of steps for "+(lowest)+" action"
you are trying to concatenate a string with a tuple (lowest - since it is either x or y, and both of them are tuples due to the assignment x=x,p1 and y=y,p2), which would require an implicit conversion from tuple to string.
To fix this, you have to convert explicitly the tuple to string (str(lowest)) (although I suspect that you actually want just one of the elements of the tuple to be displayed).

Python 3.3: How to create a loop for a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I apologize for the title not being clear, anyways how do I create a loop that will put numbers into a string, what i mean is (this is from the assignment im doing):
Enter number of courses:
Enter grade for course no. 1:
Enter weight for course no. 1:
Enter grade for course no. 2
......
Enter grade for course no. 7
......
Enter weight for course no. 9
So how would i do something like this, i have to create an input statement which has numbers in order (1-infinity but limited by number of courses). Thank you if you need anymore information or for me to clarify let me know.
You can use string formatting:
noc = int(input('Enter number of courses: '))
for i in range(1, noc+1):
grade = input('Enter grade for course no. {}: '.format(i))
weight = input('Enter weight for course no. {}: '.format(i))
#do something with grade and weight here.

Categories