Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
This is my code:
# Get the user's starting weight.
weight = input('What is your starting weight? ')
# Display the weight loss table.
for month in range(1, 7):
weight = -4
print('At the end of month', month,
'your weight will be', weight, 'lbs.')
I guess try changing:
weight = -4
To:
weight -= 4
Also make the input a string, like this:
# Get the user's starting weight.
weight = int(input('What is your starting weight? '))
# Display the weight loss table.
for month in range(1, 7):
weight -= 4
print('At the end of month', month,
'your weight will be', weight, 'lbs.')
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am in Ap computer science( i will never touch CS after this ugghhh) and have to do this python problem using While loops. The problem is:
"As a future athlete you just started your practice for an upcoming event. On the first day you run x miles, and by the day of the event you must be able to run y miles.
Calculate the number of days required for you to finally reach the required distance for the event, if you increases your distance each day by 10% from the previous day.
Print one integer representing the number of days to reach the required distance"
and so far i've come up with this:
x = int(input())
y = int(input())
days=1
while x<y:
x=x*0.1
days= days+1
you should increment your day then print it out your while loop, also only multiplying by 0.1 is like dividing by 10 so you should not forget to add your x value, try like this:
x = int(input("On the first day you run: \n"))
y = int(input("and by the day of the event you must be able to run:\n"))
day = 1
while x<y:
x += x+x*0.1
day += 1
print(f'you should run {day} days')
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 new to python and cant find where my error is. Python is saying that there is a syntax error but it wont tell me where it is. My task is to make a programme that can count a taxi fare. Here is my code.
distance = input("Enter the distance of the taxi ride in kilometers (km): ")
passengers = input("Enter the amount of passengers from 1 to 5: ")
cost = float(distance) + 3 - 1 * 2
if passengers == 5:
cost = cost * 2
print("The total cost of the journey is £" cost)
else:
print("The total cost of the journey is £" cost)
The error is probably something simple but I can't find it. Thanks in advance.
if you want to print several things with print() function, you need to separate them with commas
try this:
print("The total cost of the journey is £", cost)
You're not concatenating your strings, if you're on python 3.6 or higher use f-strings:
distance = input("Enter the distance of the taxi ride in kilometers (km): ")
passengers = input("Enter the amount of passengers from 1 to 5: ")
cost = float(distance) + 3 - 1 * 2
if passengers == 5:
cost = cost * 2
print(f"The total cost of the journey is £ {cost}")
else:
print(f"The total cost of the journey is £ {cost}")
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?"))
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.
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 am trying to make a program to calculate final grades. The user inputs x amount of assignments, and based on that I am looking to make x variables asking for the grade recieved and the weight of each assignment.
For example,
(user selects 20 assignments)
(as input):
enter assignment1 grade received,
enter assignment2 grade received,
...............
enter assignment20 grade received. (and the same for weights)
There needs to be a variable per assignment and I am unsure how to essentially convert an integer into a variable. (lists are not allowed).
Please feel free to offer suggestions. Thanks
numAssigns = input("How many assignments?: ")
marks = {}
for i in range(numAssignments):
mark = input("Enter the grade obtained on assignment %s: " %i)
weight = input("Enter the weight of assignment %s: " %i)/100
if weight not in marks:
marks[weight] = {}
if mark not in marks[weight]:
marks[weight][mark] = 0
marks[weight][mark] += 1
total = 0
for weight in marks:
for mark in marks[weight]
total += mark*weight*marks[weight][mark]
print("From all your assignments, you have %s% of the total grade of the course" %total)