Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
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.
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.
Improve this question
def _main_(userInput1):
if userInput1 ==create:
userName1=input('Please enter your username : ')
password1=input('Please enter your password : ')
createAccount(userName1, password1)
else:
userName2=input('Please enter your username : ')
password2=input('Please enter your password : ')
logIn(userName2,password2)
userInput1=input('Would you like to create a account or long in, type create or login ')
_main_(userInput1)
I keep getting an error with:
'create' is not defined
Can someone help please?
If you are checking whether userInput1 is equal to the string create, you need to put create in quotes, like this: 'create', or this "create". Otherwise, Python checks if userInput1 is equal to the variable create.
You need to change if userInput1 == create to if userInput1 == "create" as when you asked the user if they wanted to create a user, the input is by default a string and so you need quotes to tell the compiler to recognize it as a string rather than it seeing create as a variable.
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 1 year ago.
Improve this question
I'm having trouble getting Python's .upper and .lower methods to return anything. Here's the code:
initials = input("Enter your initials: ")
uppercase = initials.upper
print(uppercase)
What it returns is:
Enter your initials: mj
<built-in method upper of str object at 0x7f50734b01f0>
I originally integrated this into a larger function, but when I call uppercase later in the function the variable remains empty. I'm working in Google Colab.
To call a method in Python, you must open and close parenthesis after the name of the method:
uppercase = initials.upper()
See the example in the documentations of str.upper.
Here you go, just make sure you use .upper() method appropriately with your variable. :)
initials = input("Enter your initials: ")
print(initials.upper())
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
For some odd reason, my code won't work in Visual Studio on my laptop. It gives me errors on my script. Am I doing it wrong?
The errors I got were:
Can't assign to errorexpression --line 2
Unexpected indent --line 2
Unexpected token '<dedent>' --line 6
print("welcome user")
varpassword = input("Please enter a password: ")
if varpassword = "thisisthepassword123":
print("Welcome")
else:
print("access denied")
As others have pointed out your conditional statement should use the == operator (to indicate that you are comparing the two values to see if they're equal) instead of = that assigns the value to the variable.
if varpassword = "thisisthepassword123":
I just want to add that you should avoid using a hard-coded password value especially in python since it's plain text (unless this is just sample code to illustrate)
Edit:
Use a hashing algorithm to hash your password instead and then hash the user input and compare that. So you'll put the password through something like SHA1 or so (if you want to use a hard-coded value like "thisisthepassword123" it will have a value of f61c1bbcf1f7d68106a18bd753d4fc3c4925793f. So using a library like hashlib(https://docs.python.org/2/library/hashlib.html) you can do this:
import hashlib
hashlib.sha1(userinput).hexdigest()
Also consider using salting, read this: https://crackstation.net/hashing-security.htm
Edit 2:
Also make sure that your indentation in your script matches the indentation of your code snippet
please add == to compare = is use to assign
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 can print a string in upper case but can't get it to work when i ask the user to input a sentence. I have tried this code:
sntc = str(input ("Please enter a sentence."))
str.upper (sntc)
and this:
sntc = input ("Please enter a sentence.")
str.upper (sntc)
but none of these seem to work. Any ideas?
Python strings are immutable, so string methods like str.upper() return a new string.
So in your case, you would need to do:
upper_string = sntc.upper()
You aren't modifying the string when you use .upper() because strings are immutable. You need to assign something to what .upper() returns:
sntc = input("Please enter a sentence.")
sntc = sntc.upper()
or the shortened form:
sntc = input("Please enter a sentence.").upper()
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 8 years ago.
Improve this question
I can't get the output in python with this code.
import random
die1=random.randrange(5)
die2=random.randrange(5)
total=die1+die2
input=("\nPress the ENTER key to exit.")
The black window immediately closes when opened
You are not calling input(); you are assigning a string to the name input instead.
Remove the =:
input("\nPress the ENTER key to exit.")
Over here, you are assigning input to a tuple, ("\nPress the ENTER key to exit.").
Instead, move the equals sign to before the input:
inp = input("\nPress the ENTER key to exit.")
Here is your edited code:
import random
die1=random.randrange(5)
die2=random.randrange(5)
total=die1+die2
inp = input("\nPress the ENTER key to exit.")
Now your input will be stored in the variable inp.
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 8 years ago.
Improve this question
the python idle is throwing a error at the print() function im not sure why heres the code..
password = "cow"
name = input()
input("MR PENGUIN: hello there i am Mr Penguin what is your name? ")
input("well, hello there"+name+"Tell me your password")
input("You: my password is, ")
input("MR PENGUIN: im little defh could you repeat that? ")
input("YOU: my password is, "
print("PC POLICE: STOP! dont ever trust penguins with your data becuase he just told every one that your password is "+ password)
input("Press Enter To Exit")
You are missing a parenthesis at the end of the input on the prior line.
Change:
input("YOU: my password is, "
to:
input("YOU: my password is, ")
For the record, your print was fine. Note that when you get a cryptic error, it is often something on the previous line.
This is because your input statement in the previous line is missing a closing paranthesis.
It should be:
input("YOU: my password is, ")
instead of
input("YOU: my password is, "