Python Forum
Error in code NameError: name ' ' is not defined
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in code NameError: name ' ' is not defined
#7
I used this code below. It program works till the line with numb.x.
In 1st stage program asking for file name. (it will save the result there)
In the next stage program asks how many digits your going to input, and that and modulo 4 from that number must be equal 0.
Third stage is input digits. Till that moment it works.
After that i receive error

from typing import List, Any, TextIO
 
  
lista: List[int] = []
 
file = str(input("file name: ")+'.txt')
 
n = int(input("give how many digits u want to input, modulo 4 must be 0: \n", ))
 
while n % 4 != 0:
    n = int(input("wrong", ))
print("give " + str(n) + " digit")
 
while len(lista) < n:
 
    digit= int(input("give digit: "))
 
    if not 0 <= digit <= 9:
        print('wrong')
    else:
        lista.append(digit)
 
print(lista)
 
m = int(len(lista)/4)
 
#print(m)
numb = 0
for i in range(0, m):
 
    x = i
    y = i + 1
 
    numb.x=int(str(lista[0 + i*4]) + str(lista[2 + i*4]))
    numb.y=int(str(lista[1 + i * 4]) + str(lista[3 + i * 4]))
 
    numb.i= (numb.x) + (numb.y)
 
    chr(numb.i)
    print(chr(numb.i), end=" ")
 
file: TextIO = open((file), 'w')
file.write(chr(numb.i))
file.close()
Reply


Messages In This Thread
RE: Error in code NameError: name ' ' is not defined - by ppman00 - Sep-16-2020, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation NameError: name 'score' is not defined - Help? MrKnd94 13 4,792 Mar-06-2023, 10:54 PM
Last Post: deanhystad
  How to correct the NameError: name 'xx' is not defined? vokoyo 5 11,434 Feb-17-2021, 05:55 AM
Last Post: delonbest
  NameError: name 'os' is not defined, & load_files(sys.argv[1]) AryaIC 3 4,793 Nov-07-2020, 07:45 PM
Last Post: jefsummers
  NameError: name 'print_string' is not defined jamie_01 2 2,088 Jun-11-2020, 05:27 AM
Last Post: buran
  "NameError: name 'catName1' is not defined tofif 3 5,721 Jun-24-2019, 06:05 AM
Last Post: perfringo
  NameError x not defined Bruizeh 5 5,369 Feb-27-2019, 10:59 AM
Last Post: Larz60+
  NameError: name 'mailbox_list' is not defined pythonnewb 2 4,806 Aug-06-2017, 09:31 PM
Last Post: pythonnewb

Forum Jump:

User Panel Messages

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