This is what I have so far for my Caeser Cipher program.
import string
character = []
message = raw_input('What is your message? ').lower()
shift = raw_input('What is your shift key? ')
code = raw_input('Would you like to cipher(c) or decipher(d)? ')
if str(code) == 'd':
for character in message:
number = ord(character) - int(shift)
if number <= 96:
number = ord(character) + 26 - int(shift)
character = chr(number)
elif str(code) == 'c':
for character in message:
number = ord(character) + int (shift)
if number >= 123:
number = ord(character) - 26 + int(shift)
character = chr(number)
print(str(character))
Every time I use this program, I get back the encrypted or decrypted message of only the last letter of the line I type for the message. I'm not sure how to print my entire encrypted or decrypted message out.
The problem is that you only print once outside the for loop.
You can move the print statement inside the for loop.
if str(code) == 'd':
for character in message:
number = ord(character) - int(shift)
if number <= 96:
number = ord(character) + 26 - int(shift)
character = chr(number)
print( str(character))
elif str(code) == 'c':
for character in message:
number = ord(character) + int (shift)
if number >= 123:
number = ord(character) - 26 + int(shift)
character = chr(number)
print(str(character))
Related
these is my movie ticketing Code
x = 10
Booked_seat = 0
prize_of_ticket = 0
Total_Income = 0
Row = int(input('Enter number of Row - \n'))
Seats = int(input('Enter number of seats in a Row - \n'))
Total_seat = Row*Seats
Booked_ticket_Person = [[None for j in range(Seats)] for i in range(Row)]
class chart:
#staticmethod
def chart_maker():
seats_chart = {}
for i in range(Row):
seats_in_row = {}
for j in range(Seats):
seats_in_row[str(j+1)] = 'S'
seats_chart[str(i)] = seats_in_row
return seats_chart
#staticmethod
def find_percentage():
percentage = (Booked_seat/Total_seat)*100
return percentage
class_call = chart
table_of_chart = class_call.chart_maker()
while x != 0:
print('1 for Show the seats \n2 for Buy a Ticket \n3 for Statistics ',
'\n4 for Show booked Tickets User Info \n0 for Exit')
x = int(input('Select Option - '))
if x == 1:
if Seats < 10:
for seat in range(Seats):
print(seat, end=' ')
print(Seats)
else:
for seat in range(10):
print(seat, end=' ')
for seat in range(10, Seats):
print(seat, end=' ')
print(Seats)
if Seats < 10:
for num in table_of_chart.keys():
print(int(num)+1, end=' ')
for no in table_of_chart[num].values():
print(no, end=' ')
print()
else:
count_num = 0
for num in table_of_chart.keys():
if int(list(table_of_chart.keys())[count_num]) < 9:
print(int(num)+1, end=' ')
else:
print(int(num)+1, end=' ')
count_key = 0
for no in table_of_chart[num].values():
if int(list(table_of_chart[num].keys())[count_key]) <= 10:
print(no, end=' ')
else:
print(no, end=' ')
count_key += 1
count_num += 1
print()
print('Vacant Seats = ', Total_seat - Booked_seat)
print()
elif x == 2:
Row_number = int(input('Enter Row Number - \n'))
Column_number = int(input('Enter Column Number - \n'))
if Row_number in range(1, Row+1) and Column_number in range(1, Seats+1):
if table_of_chart[str(Row_number-1)][str(Column_number)] == 'S':
if Row*Seats <= 60:
prize_of_ticket = 10
elif Row_number <= int(Row/2):
prize_of_ticket = 10
else:
prize_of_ticket = 8
print('prize_of_ticket - ', '$', prize_of_ticket)
conform = input('yes for booking and no for Stop booking - ')
person_detail = {}
if conform == 'yes':
person_detail['Name'] = input('Enter Name - ')
person_detail['Gender'] = input('Enter Gender - ')
person_detail['Age'] = input('Enter Age - ')
person_detail['Phone_No'] = input('Enter Phone number - ')
person_detail['Ticket_prize'] = prize_of_ticket
table_of_chart[str(Row_number-1)][str(Column_number)] = 'B'
Booked_seat += 1
Total_Income += prize_of_ticket
else:
continue
Booked_ticket_Person[Row_number-1][Column_number-1] = person_detail
print('Booked Successfully')
else:
print('This seat already booked by some one')
else:
print()
print('*** Invalid Input ***')
print()
elif x == 3:
print('Number of purchased Ticket - ', Booked_seat)
print('Percentage - ', class_call.find_percentage())
print('Current Income - ', '$', prize_of_ticket)
print('Total Income - ', '$', Total_Income)
print()
elif x == 4:
Enter_row = int(input('Enter Row number - \n'))
Enter_column = int(input('Enter Column number - \n'))
if Enter_row in range(1, Row+1) and Enter_column in range(1, Seats+1):
if table_of_chart[str(Enter_row-1)][str(Enter_column)] == 'B':
person = Booked_ticket_Person[Enter_row - 1][Enter_column - 1]
print('Name - ', person['Name'])
print('Gender - ', person['Gender'])
print('Age - ', person['Age'])
print('Phone number - ', person['Phone_No'])
print('Ticket Prize - ', '$', person['Ticket_prize'])
else:
print()
print('---**--- Vacant seat ---**---')
else:
print()
print('*** Invalid Input ***')
print()
else:
print()
print('*** Invalid Input ***')
print()
(i want To add Admin login panal and Customer login panel. How to do it??. also i want seperate things in Admin panal and customer panal, to Add first the 4 options into admin panal and Add First 2 options in Customer panal .. Thanks little help would be Very Helpfull <3
This is my code:
H, M = input().split(' ')
if H == 0 and M < 45:
H = 23, M = 60 - (M-45)
elif M < 45:
M = 60 - (M-45)
else:
M = M - 45
print(H, M)
And this is the error message. I do not understand how 23 is not "literal".
H = 23, M = 60 - (M-45)
^
SyntaxError: cannot assign to literal
If you want to put multiple statements on one line (which is not recommended because it typically makes the code less readable), you need to separate them with a ; (semicolon), not a , (comma):
>>> a = 0, b = 1
File "<stdin>", line 1
SyntaxError: cannot assign to literal
>>> a = 0; b = 1
>>> a, b
(0, 1)
I have an example of a program that shows how to set up a counter for how many times each letter of the alphabet was used. I don't understand the syntax of the middle portion of the program.
LET letter$ = MID$(sentence$, LETTERNUMBER, 1)
I have tried searching on youtube and tutorials online
CLS
REM Make Counters for each Letter!!!
DIM Count(ASC("A") TO ASC("Z"))
REM Get the Sentence
INPUT "Enter Sentence:", sentence$
LET sentence$ = UCASE$(sentence$)
FOR I = ASC("A") TO ASC("Z")
LET Count(I) = 0
NEXT I
FOR LETTERNUMBER = 1 TO LEN(sentence$)
LET letter$ = MID$(sentence$, LETTERNUMBER, 1)
IF (letter$ >= "A") AND (letter$ <= "Z") THEN
LET k = ASC(letter$)
LET Count(k) = Count(k) + 1
END IF
NEXT LETTERNUMBER
PRINT
REM Display These Counts Now
LET letterShown = 0
FOR letternum = ASC("A") TO ASC("Z")
LET letter$ = CHR$(letternum)
IF Count(letternum) > 0 THEN
PRINT USING "\\## "; letter$; Count(letternum);
END IF
LET letterShown = letterShown + 1
IF letterShown = 7 THEN
PRINT
LET letterShown = 0
END IF
NEXT letternum
END
A through Z appears with the count of how many times they appeared.
The MID$ function returns a portion of a STRING's value from any position inside a string.
Syntax:
MID$(stringvalue$, startposition%[, bytes%])
Parameters:
stringvalue$
can be any literal or variable STRING value having a length. See LEN.
startposition%
designates the non-zero position of the first character to be returned by the function.
bytes%
(optional) tells the function how many characters to return including the first character when it is used.
Another method to calculate characters in a string:
REM counts and displays characters in a string
DIM count(255) AS INTEGER
PRINT "Enter string";: INPUT s$
' parse string
FOR s = 1 TO LEN(s$)
x = ASC(MID$(s$, s, 1))
count(x) = count(x) + 1
NEXT
' display string values
FOR s = 1 TO 255
PRINT s; "="; count(s); " ";
IF (s MOD 8) = 0 THEN
PRINT
IF (s MOD 20) = 0 THEN
PRINT "Press key:";
WHILE INKEY$ = "": WEND: PRINT
END IF
END IF
NEXT
END
it shall be a simple if elif(conditions) in jython, but it seems like Jython in FDMEE keeps checking for wrong result in the condition.
def Timetest(strField, strRecord):
import java.util.Date as date
import java.text.SimpleDateFormat as Sdf
import java.lang.Exception as Ex
import java.sql as sql
import java.util.concurrent.TimeUnit as TimeUnit
PerKey = fdmContext["PERIODKEY"]
strDate = strRecord.split(",")[11]
#get maturity date
strMM = strDate.split("/")[0]
strDD = strDate.split("/")[1]
strYYYY = strDate.split("/")[2]
strDate = ("%s.%s.%s" % (strMM,strDD, strYYYY))
#converting Maturity date
sdf = Sdf("MM.dd.yyyy")
strMRD = sdf.parse(strDate)
#calc date diff
diff = (strMRD.getTime()- PerKey.getTime())/86400000
diff = ("%d" % diff)
if diff>="0":
if diff <= "30":
return "Mat_Up1m " + diff
elif diff <= "90":
return "Mat_1to3m " + diff #the result goes here all the time although my diff is 367
elif diff <= "360":
return "Mat_3to12m " + diff
elif diff <= "1800":
return "Mat_1to5y " + diff #the result supposed to go here
else:
return "Mat_Over5y "+ diff
Not sure why it keeps going to the second elif instead of the fourth elif.
My calculation result of diff = 367
any idea on how to make sure that my code read the correct if elif condition?
Hope you have already figured it out, If not then check the mistakes you have made in your script.
In your script you're comparing string "367" with string values "0","90" etc., its not integer comparison, string "367" is always less than string "90" so its going into that elif condition.
Now you have to do integer comparison instead of string comparison and also move your all elif conditions inside the main if condition.
In the return statement you have to convert the interger to string to concatinate diff to a string.
Check the following code, with all the changes.
if diff>=0:
if diff <= 30:
return "Mat_Up1m " + str(diff)
elif diff <= 90:
return "Mat_1to3m " + str(diff)
elif diff <= 360:
return "Mat_3to12m " + str(diff)
elif diff <= 1800:
return "Mat_1to5y " + str(diff)
else:
return "Mat_Over5y "+ str(diff)
I have a function that allows me to add and remove character in a line by i want to limit it to around 10 characters
function love.keypressed(key, unicode)
if key == "backspace" or key == "delete" then
player = string.sub(player, 1, #player-1)
elseif unicode > 31 and unicode < 127 then
player = player .. string.char(unicode)
end
end
Could you not just restrict the length by not adding to the string if it's too long?
Or were you after something else?
function love.keypressed(key, unicode)
if key == "backspace" or key == "delete" then
player = string.sub(player, 1, #player-1)
elseif unicode > 31 and unicode < 127 and #player <=10 then
player = player .. string.char(unicode)
end
end