Python Forum
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
#1
I am trying to create a caesar shift dis-cipher but this error keeps coming up.
What am I doing wrong?

caesar code: "g fmnc wms bgblr rpylqjyrc gr zw fylb rfyrq ufyr amknsrcpq ypc dmp bmgle gr gl zw fylb gq glcddgagclr ylb rfyrq ufw rfgq rcvr gq qm jmle sqgle qrpglekyicrpylq gq pcamkkclbcb lmu ynnjw ml rfc spj"


error message: Traceback (most recent call last):
File "F:\Computing Work\Python\Program content page.py", line 50, in <module>
julius()
File "F:\Computing Work\Python\Program content page.py", line 35, in julius
cracked=num_to_let(a[counter],z)
File "F:\Computing Work\Python\Program content page.py", line 21, in num_to_let
g = z + let_to_num(num)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

#Variables
y=0 #Variable for while loop
alphabet=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "]

#function takes a 2 numbers then 
def power():
    a=int(input("Enter number: "))
    b=int(input("Enter power: "))
    print(a**b)
#Takes a letter and gives you the numerical postion in the alphabet
def let_to_num(x):
    for i in range(0,26):
        if(x==alphabet[i]):
            c=int(i)
            return(int(c))
        else:
            print("nonono")
#Takes a number and a shift value and performs a calculation to attain the postion of the result in the alphabet
def num_to_let(num, z):
    g = 0
    g = z + let_to_num(num)
    return(alphabet[g])
#Performs a caesar shift decryption
def julius():
    z=0
    counter=1
    a=str(input("Enter sentence: "))
    b=str(input("Enter 1st letter: "))
    c=str(input("Enter 2nd letter: "))
    letA=let_to_num(b)
    letB=let_to_num(c)
    z=letA-letB
    cracked=[]
    for i in range(0,len(a)):
        cracked=num_to_let(a[counter],z)
        
        counter+=1
    print(cracked)
        
        
        
    
    
#Menu loop
while(y==0):
    ans=int(input("***Programs***\n 1) Powerer\n 2) Caesar Cipher"))
    if(ans==1):
        power()
    elif(ans==2):
        julius()
    else:
        print("3")
Reply
#2
(Jul-19-2017, 07:32 PM)William_the_Conqueror Wrote:
def let_to_num(x):
    for i in range(0,26):
A space is not in the first 26 indices of alphabet, though.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question TypeError: argument of type 'NoneType' is not iterable Tajaldeen 7 2,122 Nov-29-2024, 09:45 AM
Last Post: Tajaldeen
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 3,431 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 13,543 Aug-24-2023, 05:14 PM
Last Post: snippsat
  Type Error: Unsupported Operand jhancock 2 4,590 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 6,720 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 11,241 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 3,529 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 35,140 May-07-2022, 08:07 AM
Last Post: menator01
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 3,854 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 8,668 Apr-13-2021, 07:50 AM
Last Post: Anldra12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020