Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Hey is there a way to print inputs like this:
Input:
Enter the minimum number of feet (not less than 0):
5
Enter the maximum number of feet (not more than 99):
10
How can one do this?
Simply add a new line to the input prompt with \n (Python newline character) like this:
minFeet = input("Enter the minimum number of feet (not less than 0): \n")
maxFeet = input("Enter the maximum number of feet (not more than 99): \n")
You can just do it like this:
print("Enter the minimum number of feet (not less than 0):")
minN = input()
print("Enter the maximum number of feet (not more than 99):")
maxN = input()
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I created an input() and I want user to enter specific values like kg or KG or Kg and make any other values return "invalid entry"
when I try to assign other values to the variable unit1, it is taking the last entry or it throws an error
That's my code:
weight=int(input("Enter weight: "))
unit= input("Kg or Lbs: ")
unit1= "kg"
unit2="Lbs"
if unit==unit1:
print(weight/0.45)
elif unit==unit2:
print(weight*0.45)
else:
print("invalid entry")
You should change the casing of the strings to the same. String comparisons are case sensitive, so the string Lbs is not same as lbs
str.lower() is your friend here :)
You should also check to make sure someone is entering an integer for your weight so your code doesn't crash. Try this!
while True:
try:
weight=int(input("Enter weight: "))
break
except:
print("Invalid value entered for weight")
unit= input("Kg or Lbs: ")
unit1= "kg"
unit2="lbs"
if unit.lower()==unit1:
print(weight/0.45)
elif unit.lower()==unit2:
print(weight*0.45)
else:
print("invalid entry")
You could also use string.upper() in case this suits you more
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this code here:
def maximum():
i = int(float(input("What is the maximum value?")))
if i < 1.2:
return print("ERROR: Maximum should be greater than 1.2"), maximum()
else:
return i
maximum()
But it doesn't let me use numbers between 0-1.9 showing an output of
What is the maximum value?1.2
ERROR: Maximum should be greater than 1.2
What should I change in the function to allow decimals to be accepted?
Remove the conversion to an int, as this will floor your float.
def maximum():
i = float(input("What is the maximum value?"))
if i < 1.2:
return print("ERROR: Maximum should be greater than 1.2"), maximum()
else:
return i
maximum()
int means integer, i.e. a whole number. When you call int, you're truncating (rounding down) to the nearest whole number, so any numbers from 1.0 to 1.9 just get truncated to 1, which is less than 1.2. You don't need the int call if you want a fractional number.
i = float(input("What is the maximum value?"))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to make a basic program that gets the name from a user and makes a "lucky number" by just adding a number based on if it greater or less than another number. What am i doing wrong here?
myName = input('Insert name: ')
myLuckynumber = int(input('Insert a number 1-9: '))
if myLuckynumber > 5:
Newlucky = int(myLuckynumber + 3)
print('Hello '+myName+'your lucky number is: '+Newlucky)
elif myLuckynumber < 5:
newLucky = int(myLuckynumber + 4)
print('Hello '+myName+'your lucky number is: '+newLucky)
else:
print('try again!')
You cannot add a str to an int, they need to be strings to concatenate
print('Hello '+myName+'your lucky number is: '+ str(Newlucky))
Or using something like str.format
print('Hello {} your lucky number is: {}'.format(myName, Newlucky))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am new in python, i want to do is limit the float input by the user only upto two decimal point, eg: 1.11, user is not allowed to input 1.111 or more than to after two decimal point . Thank you
You cannot restrict what the user inputs, but you can convert a float to have 2 decimal points:
value = float(input("Input your number: "))
print ("You inputted " + str(value))
new_value = "{:.2f}".format(value)
print ("After formatting, your number has become: " + str(new_value))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need help with creating a table. The question is asking me to write a function that outputs a two column table of kilogram weights and their pound equivalents for kilogram values 0, 10, 20 ..., 100.
So far I have:
kilos = eval(input("Enter a weight in kilograms: "))
pounds = 2.2 * kilos
print("The weight in pounds is", pounds)
but I have no idea how to construct this as a table.
By table I assume that you are trying to print the output on console.
mult_factor = 2.20462
print ('Kilogram', 'Pound')
for i in range (0, 100, 10):
print (i , i * mult_factor)