You are Here: Home >< GCSEs

# Computing - Pytnon watch

1. Hi, I am currently trying to write a program, for school, in order to encrypt and de-rypt a inputted message. My code currently works but it is not fully complete. I am having trouble trying to allow it to enter an offset from values from 2-26 and I am having trouble making it repeat the question then carry on with the code until it gets the correct value. Right now it just says invalid message when a wrong number is entered but still carries on with the code. Also I need the encrypted or decrypted message to only be in the alphabet no other symbols or keys. Can anyone help please? This is my code currently.

result = ''
message = ''
choice = ''

offset=int(input("Enter an offset: "))
if offset >25 or offset <0:
print("Invalid offset, please enter another offset: ")
else:
print("Okay")

while choice != '3':
choice = input("\nDo you want to encrypt or decrypt the message?\nEnter 1 to Encrypt, 2 to Decrypt, 3 to Exit Program: ")

if choice == '1':
message = input("\nEnter the message to encrypt: ")

for i in range(0, len(message)):
result = result + chr(ord(message[i]) - offset)

print (result + '\n\n')
result = ''

elif choice == '2':
message = input("\nEnter the message to decrypt: ")

for i in range(0, len(message)):
result = result + chr(ord(message[i]) + offset)

print (result + '\n\n')
result = ''

elif choice != '3':
print ("You have entered an invalid choice. Please try again.\n\n")
2. Go to StackOverflow and post this question. You'll get more responses there.

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: February 14, 2016
Today on TSR

### The most controversial member on TSR?

Who do you think it is...

### Is confrontation required?

Discussions on TSR

• Latest
Poll
Useful resources

## Study tools

### Essay expert

Learn to write like a pro with our ultimate essay guide.

See where you can apply with our uni match tool

### Make study resources

Create all the resources you need to get the grades.

### Create your own Study Plan

Organise all your homework and exams so you never miss another deadline.

### Resources by subject

From flashcards to mind maps; there's everything you need for all of your GCSE subjects.

### Find past papers

100s of GCSE past papers for all your subjects at your fingertips.

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE