-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4 Paridad.py
177 lines (165 loc) · 7.07 KB
/
4 Paridad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from random import randint
f=open('Paridad.txt','a')
estado=0
from tkinter import *
def Graficar():
ventana = Tk()
c = Canvas(ventana,width=500,height=500)
ventana.geometry("500x500")
c.create_oval(33,30,320,317,fill="Cyan")
c.create_oval(48,45,305,302,fill="White")
c.create_oval(41,41,126,126,fill="pink")####
c.create_oval(56,56,109.5,109.5,fill="pink")
c.create_oval(226,226,311,311,fill="pink")#abaj dere
c.create_oval(41,226,126,311,fill="pink")#abaj izq
c.create_oval(226,41,311,126,fill="pink")#arri dere
c.create_oval(44,104,54,115,fill="black")
c.create_oval(55,226,66,237,fill="black")
c.create_oval(300,104,310,115,fill="black")
c.create_oval(285,236,296,225,fill="black")
c.create_oval(224,296,235,285,fill="black")
c.create_oval(108,306,119,295,fill="black")
c.create_oval(103,51,114,40,fill="black")
c.create_oval(226,64,237,53,fill="black")
estado0=Label(ventana,text="q0",bg="pink",font="Helvetica 16").place(x=68,y=68)
estado1=Label(ventana,text="q1",bg="pink",font="Helvetica 16").place(x=255,y=68)
estado2=Label(ventana,text="q2",bg="pink",font="Helvetica 16").place(x=68,y=255)
estado3=Label(ventana,text="q3",bg="pink",font="Helvetica 16").place(x=255,y=255)
cero1=Label(ventana,text="0",bg="white",font="Helvetica 12").place(x=288,y=170)
cero2=Label(ventana,text="0",font="Helvetica 12").place(x=323,y=170)
cero3=Label(ventana,text="0",bg="white",font="Helvetica 12").place(x=50,y=170)
cero4=Label(ventana,text="0",font="Helvetica 12").place(x=15,y=170)
uno1=Label(ventana,text="1",bg="white",font="Helvetica 12").place(x=167,y=47)
uno2=Label(ventana,text="1",font="Helvetica 12").place(x=167,y=6)
uno3=Label(ventana,text="1",bg="white",font="Helvetica 12").place(x=167,y=277)
uno4=Label(ventana,text="1",font="Helvetica 12").place(x=167,y=320)
c.create_line(10,80,41,80,fill="black")
c.create_oval(38,77,43,84,fill="black")
inicio=Label(ventana,text="inicio",font="Helvetica 10").place(x=9,y=46)
c.place(x=0,y=0)
ventana.mainloop()
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")
while(c!='s'):
if(c=='m'):###########################################################
cad=input("introduce la cadena: ")
f=open('Paridad.txt','a')
f.write("\n\nMODO MANUAL\n")
f.write("-q0-\n")
for i in cad:
f.write(i+" ")
if(i=='1'):
if(estado==0):
estado=1
print("q"+str(estado))
f=open('Paridad.txt','a')
f.write("q"+str(estado)+"\n")
elif(estado==1):
estado=0
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
elif(estado==3):
estado=2
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
else:
estado=3
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
elif(i=='0'):
if(estado==0):
estado=2
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
elif(estado==2):
estado=0
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
elif(estado==1):
estado=3
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
else:
estado=1
print("q"+str(estado))
f.write("q"+str(estado)+"\n")
else:
print("invalido")
if(int(estado)==0): #en if estado se castea con int... en print con str
estado=0
print("Hay paridad de ceros y unos")
f.write("\nHay paridad de ceros y unos\n")
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")
else:
estado=0
print("NO hay paridad de ceros y unos")
f.write("\nNo hay paridad de ceros y unos\n")
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")
elif(c=='a'):##############################################################
long=randint(0,1000)#
print("longitud: "+str(long))
f=open('Paridad.txt','a')
f.write("\n\nMODO AUTOMATICO\n")
f.write("\nlongitud: "+str(long))
cad3=""
for h in range(0,long):#
cad2=str(randint(0,1))
cad3=str(cad3+cad2)
print(""+str(cad3))
print("q0, ")
f.write("\n"+str(cad3)+"\n")
f.write("\nq0, ")
for i in cad3:
if(i=='1'):
if(estado==0):
estado=1
print("q"+str(estado))
f.write(" q"+str(estado)+" = 1,")
elif(estado==1):
estado=0
print("q"+str(estado))
f.write(" q"+str(estado)+" = 1,")
elif(estado==3):
estado=2
print("q"+str(estado))
f.write(" q"+str(estado)+" = 1,")
else:
estado=3
print("q"+str(estado))
f.write(" q"+str(estado)+" = 1,")
elif(i=='0'):
if(estado==0):
estado=2
print("q"+str(estado))
f.write(" q"+str(estado)+" = 0,")
elif(estado==2):
estado=0
print("q"+str(estado))
f.write(" q"+str(estado)+" = 0,")
elif(estado==1):
estado=3
print("q"+str(estado))
f.write(" q"+str(estado)+" = 0,")
else:
estado=1
print("q"+str(estado))
f.write(" q"+str(estado)+" = 0, ")
else:
print("invalido")
if(int(estado)==0):
estado=0
print("Hay paridad de ceros y unos")
f.write("\nHay paridad de ceros y unos\n")
f.close()
c=input("Introducir m(manual), a(automatico), g(ver grafico) s(salir): ")
else:
estado=0
print("NO hay paridad de ceros y unos")
f.write("\nNo hay paridad de ceros y unos\n")
f.close
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")
elif(c=='g'):##############################################################
Graficar()
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")
else:
print("\nopcion no valida")
c=input("Introducir m(manual), a(automatico), g(ver grafico), s(salir): ")