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
Struggling with this one. Only a beginner so go easy on me! :)
Trying to have user input password and if not within 6-10 characters. They are asked to input again.
When password correct the loop stops.
I can’t seem to get it to exit the loop even if correct lenght password entered.!
min_password_lenght = 6
max_password_lenght = 10
password = input(“enter password:”)
password_lenght = len(password)
while password_lenght > 6 or password_lenght < 10:
print(“error”)
password = input(“enter again:”)
print (“password correct”)
You should probably be more specific next time, but here's a snippet that satisfies what you described:
pwd = ""
while len(pwd) < 6 or len(pwd) > 10:
pwd = input("Enter password: ")
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 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 2 years ago.
Improve this question
This is a easy question but i need explanation.
In this code Why the output is 100:
x = 100.1205
y = str(x)[6]
print("{:.{}f}".format(x,y))
x = 100.1205
y = str(x)[6] ## This is turning x into a string and grabbing the 6th character which is 0
print("{:.{}f}".format(x,y)) # this is saying print x to the decimal place
#specified by the value of y (zeroth digit) which is 100
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()
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 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=")