This question already has answers here:
How to test multiple variables for equality against a single value?
(31 answers)
Closed 4 years ago.
To provide some context, I am looking to create a program that will encrypt and decrypt through the Caesar cipher, and I have created code for both of these functions that works quite well. However, when I try to conjoin these into one code I find that it always ignores the if statements I have in place and will always try to encrypt what the user enters. Any help would be much appreciated!
characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.`~#$£%^&*()_+-=[]{}|;:<>,/"
translated = ""
print("Welcome to Krypto! ")
decision = input("What would you like to do today? (encrypt, decrypt, info) ")
message = input("Please enter the text you would like to manipulate: ")
if decision == 'encrypt' or 'Encrypt':
print ("Encrypt selected")
#encryption begins
elif decision == 'decrypt' or 'Decrypt':
print("Decrypt selected")
#decryption begins
or 'Encrypt'
This is always True
Related
This question already has answers here:
String contains any character in group?
(5 answers)
Closed last year.
I want to check if username has any Character from blockCharacter but i could'nt do it and this is my code
user = input("Whats your name\n").lower()
user = (user.title())
BlockChar = ["+","none","-"]
if user == BlockChar:
print("That does'nt not feels right. Try Again")
breakpoint
print ("Welcome " + user)
I am new to codeing and stack overflow so i need some help with it
The any function and a generator expression will work quite nicely to determine if any of the strings in BlockChar are in your user string.
if any(ch in user for ch in BlockChar):
...
This question already has answers here:
Asking the user for input until they give a valid response
(22 answers)
Closed 1 year ago.
I'm a beginner in Python. I've tried using the 'while' loop. I need the code to allow the user to reattempt the question after their previously incorrect guess. After the first correct try, it says what I want it to say but after the first wrong try, the correct answer is given as incorrect. How do I solve this and what am I doing wrong?
key = input("Choose a place and see if your guess is correct! ")
if key == ("bed"):
print("Congratulations! You are correct and will now progress to room 2.")
while key != ("bed"):
input("Unfortunately your guess is incorrect. Try again. ") ```
First of all you need to indent the 2nd line. Second of all the loop can't work because you say that the loop should stop when the key is "bed" but you do not change the key. The 4th line should be: key = input("Unfortunately your guess is incorrect. Try again. ")
Of course you need to put your if statement in the while loop.
while(True):
if key == ("bed"):
print("Congratulations! You are correct and will now progress to room 2.")
False
else:
key = input("Unfortunately your guess is incorrect. Try againg.")
maybe try it like "this"?
This question already has answers here:
How to read a file without newlines?
(12 answers)
Closed 5 years ago.
I have looked over the answers given on other questions. But they are not making any sense to me sorry. I have a notepad document that I want to check to see if the name that you give the program is in the document and if it is. it says hello and let you access the program and lets you do stuff. If your name is not it the program I want it to say that you do not have an account and ask you if you want to make an account and if you say yes then you give it your name and it adds it to the text document. The problem that I am having is that it does not see if your name is in the text document but when you print the names it gives you them and they look like this. 'Coryn\n' and I have no clue what this means. My code is down below.
def AI():
name = raw_input("Hello my name is Cora I am an artificial helper. What is your name? ")
yes1 = ""
name_list = list(open('r','\\\\ph-fss1\\Students\\S39055\\Desktop\\names.txt'))
for names in name_list:
if name in name_list:
print "Welcome back sir"
else:
yes1 = raw_input("You do not have an account do you wish to make one? yes/no ").lower()
if yes1 == "no":
break
if yes1 == "yes":
name('w',open('\\\\ph-fss1\\Students\\S39055\\Desktop\\names.txt'))
You need to split the lines to make them 'readable' for the AI. str.splitlines Docs
This question already has answers here:
How do I read from stdin?
(25 answers)
Closed 17 days ago.
For example, if the program asks the user to press enter on their keyboard to continue, the program can recognise it & continue. I'm still a student so not really sure, is it possible..?
I think you are looking for input command
You need to use the input statement and assign the input to variables like this:
name = input("What's your name? ")
print("Hello there, " + name + "!")
It's that simple!
Use the input function as well as if statements:
x = input("What's 1+1?")
if x == 2:
print("correct")
else:
print("Wrong")
This question already has answers here:
How to test multiple variables for equality against a single value?
(31 answers)
Closed 7 years ago.
import operator
import csv
question= input("Are you a student or teacher: ")
if question=="student" or "s" or "Student":
print("You are using the wrong program. Please use the arithmetic quiz")
elif question=="teacher" or "t" or "Teacher":
print("Hello and welcome to the program which lets you see your students' scores in the arithmetic quizes")
In this code I have tried to use if else statements, but it doesnt work.
I have already tried several ways to make it work but it doesnt.
You could check if the input is in a tuple:
question= input("Are you a student or teacher: ")
if question in ("student", "s", "Student"):
print("You are using the wrong program. Please use the arithmetic quiz")
elif question in ("teacher", "t", "Teacher"):
print("Hello and welcome to the program which lets you see your students' scores in the arithmetic quizes")