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 7 years ago.
Improve this question
So I get this error when I run the program, I am not sure why this is not working.
C:\Python27>python bmi.py
File "bmi.py", line 11
def getweight(wt)
^
SyntaxError: invalid syntax
print('BMI Calculator!')
#declaring my variables
ht=height
wt=weight
bm=bmi
#Calling my main function
main()
#getting user input for weight in pounds
def getweight(wt)
weight = int(input('Please enter your weight input pounds(whole number): '))
return(wt)
#getting user input for height in inches
def getheight(ht)
height = int(input('Please enter your height input in inches(whole number): '))
return(ht)
#function for the bmi calculator
def bmicalc()
bmi = (wt*703)/(ht*ht)
#main function
def main()
getweight()
getheight()
bmicalc()
You need a colon at the end of your function declaration. Like so:
def foo(bar):
pass
Related
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 months ago.
This post was edited and submitted for review 4 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I am unable to solve this.
Problem Statement:-
Make use of while loop and print all positive even numbers smaller than or equal to the number given by the user
e.g.:-
User Input: 6
Output: 2, 4, 6
I have tried this but the code is running into an infinite loop.
num = int(input("Please enter an even number: "))
i = 0
while num >= i :
if num % 2 == 0:
print(num)
i = num + 1
Thank you.
Don't use a while loop here, just use a for loop:
num = int(input("Please enter an even number: "))
for nr in range(0, num, 2):
print(nr)
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
Here is the code
wagesAmount = float(input("Enter Wages Amount: "))
numberOfHours = float(input("Enter Number Of Hours Worked: "))
totalWagesAmount = (wagesAmount) * (numberOfHours)
if totalWagesAmount > "0":
printtotalWagesAmount
I need to add an else statement as well but I was just trying to troubleshoot this issue first
"0" means it's a string . so when u wanna do if something > 0: thats means that 0 is integer and you say (if somthing > "0" string. so you
wagesAmount = float(input("Enter Wages Amount: "))
numberOfHours = float(input("Enter Number Of Hours Worked: "))
totalWagesAmount = (wagesAmount) * (numberOfHours)
if totalWagesAmount > 0:
print (totalWagesAmount)
You have to remove the "" on 0 because "0" != 0
if totalWagesAmount > 0:
Writing "0" means its string because of dynamic typing in 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 2 years ago.
Improve this question
I am trying to find the percentage of questions right but my percentage code is returning (100, 1) but I want it to return 100. My code is
accuracy = 100 # Setting a default.
def percentage(part, whole):
return(round((part/whole)*100),1)
and the code to print is
accuracy = percentage(questionsright, questionscompleted)
print("Your accuracy is now " + str(accuracy) + "% .")
Does anybody know why it isn't returning 100? Please Help.
You have parenthesis in the wrong places in this function:
def percentage(part, whole):
return(round((part/whole)*100),1)
Without the change, your function was returning an ordered tuple of two elements where the first element is round((part/whole)*100) and the second is 1.
Here is the corrected function:
def percentage(part, whole):
return round((part/whole)*100,1)
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 want the code to ask for the radius and length then the program will calculate piradiusradius*length from the definition area the print out the radius for example if at asks me the radius i put 5 same with the length it should say the volume is 392.75
def calculate_volume(radius, length):
pi=3.142
vol=pi*radius*radius*length
#main program
radius = int(input("enter radius: "))
length = int(input("enter length: "))
volume = calculate_volume(radius, length)
print("the volume: ",volume)
You are missing the return statement:
def calculate_volume(radius, length):
pi = 3.142
vol = pi * radius * radius * length
return vol
The example is almost correct, you just haven't returned a result from your function!
def calculate_volume(radius, length):
pi=3.142
vol=pi*radius*radius*length
return(vol)
When you put volume = calculate_volume(radius, length) right now volume is being set to None instead of vol from inside of the function.
Or better yet -- Get in the habit of using type hints - then use a decent IDE (such as PyCharm), or a type checker (such as MyPy). PyCharm would have given you a warning that you didn't have a return statement -- and anything calling your function would know the types of parameters and the return type.
def calculate_volume(radius: float, length: float) -> float:
pi = 3.142
vol = pi*radius*radius*length
return vol
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 want to make sure that the user inputs a name which is more than 3 letters, or else the program will have to repeat the question until the user inputs something which is acceptable.
while True:
if len(name) < 3
name = input("What is the student\'s name?")
For example:
name = ""
while len(name) < 3:
name = input("What's the student's name?")
#if python2:
#name = raw_input("What's the student's name?")
EDIT:
Worth to remember that in Python2 input tries to "guess" input type and if someone will provide for example "23" input will parse it to int and len(name) will throw exception. To avoid it it might be usefull to call raw_input instead of input.
In Python3 input returns string.
You mean something like this?
x = ""
y = input("Insert Y=")
while len(x) < y:
x = input("Insert X=")