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 days ago.
Improve this question
Code project: Registration form
The form has a name field, which should be more than 3 characters long.
Any name that has less than 4 characters is invalid.
Complete the code to take the name as input, and raise an exception if the name is invalid, outputting "Invalid Name". Output "Account Created" if the name is valid.
Sample Input
abc
Sample Output
Invalid Name
please help me out to complete the code.
try:
name = input()
raise ValueError("Invalid Name!")
except:
print("Invalid Name")
Related
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 months ago.
Improve this question
I was wondering is it possible to let a user enter any number of words one per line using the input function. So for example, let's say I have the following prompt:
Enter any number of words, one per line, or a blank line to stop:
and the output is something like this:
hello
my
name
is
dave
What would the code for this look like?
simply :
while True:
x = input()
if x == '':
break
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
answer=input(print('What s the capital',country,'?'))
RETURN
What s the capital of South Africa ?
None
And I have to put my answer just after the 'none'
You are printing inside the input function and print returns None.
You should do something like this:
country = "Italy"
answer = input(f"What's the capital of {country}? ")
print(answer)
Read the documentation here.
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 want to add a error message if it exceeds 12 or if a character is entered without any if statements. here is what I have written so far:
import calender
def get_mont_name(month_number):
try:
return calender.month_name[month_number]
except IndexError:
print("'[]' is not a valid month number".format(month_number))
Your code is really close to working!
Firstly, you've spelt calendar wrong, but I assume this is just a typo.
You've slightly misused format() which is probably causing your issue. Replacing your print statement with the following should fix it:
print("{num} is not a valid month number".format(num = month_number))
The curly brackets allow the format() method to identify the parts of the string you'd like to modify.
I hope this helps!
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 am having a sentence as below
Eg:
Original Strings can be in below formats.
"[PartnerID:2012345][Failure] Caused by :This is the Failure Name"
"[Failure] caused by This is the failure name"
"Reliability: oscrash in This is the failure name"
I want the string to be trimmed to This is the Failure Name.
Can anyone please help me in writing code for this in python?
Sorry, I had left out other sentences before
Let:
str1 = "[PartnerID:2012345][Failure] Caused by :This is the Failure Name"
To get what you require, we split:
res = str1.split(":")[-1]
if it is like:
str1 = "[PartnerID:2012345][Failure] Caused by This is the Failure Name"
then you can:
res = str1.split("Caused by ")[-1]
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 8 years ago.
Improve this question
name = input("What is your name?")
if name = Bob:
print ("Hi")
I am a beginner in python so it would be greatly appreciated if you would give an explanation or simple answer
-thanks
if name == "Bob":
print ("Hi")
Use == for comparison, and string variables should be within quotes:
if name == "Bob":
print ("Hi")