-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mundo-03.py
2324 lines (2039 loc) · 69.3 KB
/
Mundo-03.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ENCODING: UTF-8
# TUPLAS SÃO IMUTÁVEIS
# lanche = ('hambuger', 'suco', 'pizza', 'pudim', "Batata Frita")
# print(lanche[-2::-1])
'''for count in range(0, len(lanche)):
print(f"Vou comer {lanche[count]} na posição {count}")
print("Comi pra caramba")'''
'''for comida in lanche:
print(f"Vou comer {comida}")
print("Comi pra caramba")
'''
'''for pos, count in enumerate(lanche):
print(f"Vou comer {count}, na posição {pos}")
print("Comi pra caramba")'''
# print(sorted(lanche))
'''a = (1, 4, 7, 2)
b = (7, 9, 0, 1)
c = a + b
d = sorted(c)'''
# print(sorted(c))
# print(c.count(1))
'''print(d)
print(d[2])
print(f"temos {c.count(7)} número 7")
print(f"A sua primeira posição do 7 é {c.index(7)}")
print(f"A sua segunda posição do 7 é {c.index(7, 2+1)}")'''
'''pessoa = ("Johnny", 27, 1.70, 1,68, "M")
del(pessoa)
print(pessoa)'''
# CHALLENGE 72
# Crie um programa que tenha uma tupla totalmente preenchida com uma contagem por extenso, do zero até vinte.
# Seu programa deverá ler um numero pelo teclado (entre 0 e 20) e mostrá-lo por extenso
'''numExtenso = ("Zero", "One", "Two", "Tree", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty")
# numeral = int(input("Enter any number between '0' and '20': "))
# if(numeral > 20):
# while(numeral > 20):
while True:
numeral = int(input("Enter any number between '0' and '20': "))
if(numeral <= 20):
print(f"You have chose {numeral} in numeral and this number in extensive is {numExtenso[numeral]}")
else:
continue
c = str(input("Would you like keeping ? [Y / N]: ")).strip()
if(c in "Nn"):
break
print("You have decided to quit of the program!")'''
# CHALLENGE 73
# Crie uma tupla preenchida com os 20 primeiros colocados da Tabela do Campeonato Brasileiro de Futebol,
# na ordem de colocação. Depois mostre: a) Os 5 primeiros times. b) Os últimos 4 colocados.
# c) Times em ordem alfabética. d) Em que posição está o time da Chapecoense.
'''times = ("São Paulo", "Vasco", "Botafogo", "Cruzeiro", "Flamengo", "Coritiba", "Juventude", "Arsenal", "Man Unt", "Milan", "Liverpool",
"Inter Milão", "Real Madrid", "Barcelona", "Bayer Muniq", "Chelsea", "PSG", "Palmeiras", "Corinthians", "Zenit", "Man City")
rank = 0
print(("=="*20))
print(f"This is the list of clubs!\n{times}")
print(("=="*20))
print(f"These are the rankings of the top 5 on the soccer table:\n{times[0:5]}")
print(("=="*20))
print(f"These are the rankings of the last 4 on the soccer table:\n{times[-4:len(times):1]}")
print(("=="*20))
print(f"This is the list of the club's classification in sort:\n{sorted(times)}")
print(("=="*20))
print(f"Barcelona club it is in the position {times.index('Barcelona')+1}ª of the classification!")
print(("=="*20))
for pos in times:
if(pos != "Barcelona"):
rank += 1
if(pos == "Barcelona"):
break
print(f"Barcelona club it is in the position {times.index(pos)+1}ª of the classification!")'''
# CHALLENGE 74
# Crie um programa que vai gerar cinco números aleatórios e colocar em uma tupla.
# Depois disso, mostre a listagem de números gerados e também indique o menor e o maior valor que estão na tupla.
'''from random import randint
# for tupla in range(random.randint(0, 10), 5):
# lista = tupla
# print(lista)
# tupla1 =
# tupla2 =
# tupla3 =
# tupla4 =
# tupla5 =
c = m = n = tupla = 0
e = f = 0
# tupla1 = tupla2 = tupla3 = tupla4 = 0
while(c != 5):
# a = randint(0, 10)
# print("numeros do A", a)
# b = randint(0, 10)
# print("numeros do B", b)
# d = randint(0, 10)
# print("numeros do D", d)
# e = randint(0, 10)
# print("numeros do E", e)
# f = randint(0, 10)
# print("numeros do F", f)
# print()
# tupla = tupla.split()
# if(c == 0):
# m = n = a = b = d = e = f
a = randint(0, 10)
print("numeros do A", a)
b = randint(0, 10)
print("numeros do B", b)
d = randint(0, 10)
print("numeros do D", d)
e = randint(0, 10)
print("numeros do E", e)
f = randint(0, 10)
print("numeros do F", f)
if(c == 0):
m = n = a
# else:
if(a > m):
m = a
if(b > m):
m = b
if(d > m):
m = d
if(e > m):
m = e
if(f > m):
m = f
if(a < n):
n = a
if(b < n):
n = b
if(d < n):
n = d
if(e < n):
n = e
if(f < n):
n = f
# tupla = tuple(tupla)
tupla = ((a), (b), (d), (e), (f))
c = 5
print(f"The drawn numbers was: {tupla}")
print(f"The bigger number was {m}")
print(f"The lower number was {n}")'''
# b = str(a)
# tupla1 = str(a)
# del(a)
# d = str(a)
# tupla2 = b + tupla1
# del(b)
# e = str(d)
# tupla3 = e + tupla1 + tupla2
# del(d)
# f = str(e)
# tupla4 = f + tupla1 + tupla2 + tupla3
# del(e)
# g = str(f)
# tupla5 = g + tupla1 + tupla2 + tupla3 + tupla4
# del(f)
# total = list(tupla5)
# print(d)
# SOLUTION FROM GUANABARA
'''from random import randint
n = (randint(1, 10), randint(1, 10), randint(1, 10), randint(1, 10), randint(1, 10))
# print(f"The numbers draws were:", n)
print("The numbers draws were: ", end="")
for a in n:
print(a, end=" ")
print()
print(f"The biggest number draw was {max(n)}")
print(f"The lowest number draw was {min(n)}")'''
# CHALLENGE 75
# Desenvolva um programa que leia quatro valores pelo teclado e guarde-os em uma tupla. No final, mostre:
# A) Quantas vezes apareceu o valor 9. B) Em que posição foi digitado o primeiro valor 3.
# C) Quais foram os números pares.
'''total = 0
val1 = int(input("Enter with any number: "))
val2 = int(input("Enter with any number: "))
val3 = int(input("Enter with any number: "))
val4 = int(input("Enter with any number: "))
tupla = ((val1), (val2), (val3), (val4))
print(tuple(tupla))
print(f"The total of times that showed the number off '9' is {tupla.count(9)}")
if(3 not in tupla):
print(f"The number '3' was not enter any time.")
else:
print(f"The number '3' is in position {tupla.index(3)+1}ª")
count = 0
for pos, a in enumerate(tupla):
if(a % 2 == 0):
count += 1
if(count == 1):
total = (a)
total2 = total
del(a)
if(count == 2):
total1 = a
total2 = (total, total1)
# del(a)
if(count == 3):
total3 = a
total2 = (total, total1, total3)
# del(a)
if(count == 4):
total4 = a
total2 = (total, total1, total3, total4)
# del(a)
# if(val2 % 2 == 0):
# count += 1
print(f"We hava till now {count} even numbers and its positions is {pos+1}")
print(f"The total of even numbers is {count} and they are {total2}")'''
# SOLUTION FROM GUANABARA
'''núm = (int(input("Enter with a number: ")), int(input("Enter with one more number: ")),
int(input("Enter with another number: ")), int(input("Enter with the last number: ")))
print(f"You have entered the numbers: {núm}")
print(f"The value of '9' appeared {núm.count(9)} times")
if(3 in núm):
print(f"The number '3' is it in {núm.index(3)+1}ª position")
else:
print(f"The value of '3' is not entered at not of position!")
print(f"The quantity of even number are: ", end="")
for n in núm:
if(n % 2 == 0):
print(n, end=" ")'''
# CHALLENGE 76
# Crie um programa que tenha uma tupla única com nomes de produtos e seus respectivos preços, na sequência.
# No final, mostre uma listagem de preços, organizando os dados em forma tabular.
'''# price = (1.75, 2.00, 15.90, 25.00, 4.20, 9.99, 120.32, 22.30, 34.90)
count = 0
listing = ("Pencil", 1.75, "Eraser", 2.00, "notebook", 15.90, "Pencil Case", 25.00, "Protractor", 4.20, "Compass", 9.99, "Schoolbag", 120.32, "Pens", 22.30, "Books", 34.90)
# print(listing[2], "R$", listing[3])
for pos, products in enumerate(listing):
print(products[count], end="..............R$: ")
count += 1
print(listing[count])
# print(price)'''
# SOLUTION FROM GUANABARA
'''listing = ("Pencil", 1.75, "Eraser", 2.00, "notebook", 15.90, "Pencil Case", 25.00,
"Protractor", 4.20, "Compass", 9.99, "Schoolbag", 120.32, "Pens", 22.30, "Books", 34.90)
# print(len(listing))
print(f"{'='*30}")
print(f"{'LIST OF PRICES':^25}")
print("="*30)
for pos in range(0, len(listing)):
if(pos % 2 == 0):
print(f"{listing[pos]:.<30}", end="R$")
else:
print(f"{listing[pos]:>7.2f}")'''
# CHALLENGE 77
# Crie um programa que tenha uma tupla com várias palavras (não usar acentos).
# Depois disso, você deve mostrar, para cada palavra, quais são as suas vogais.
'''lotWords = ("rice", "mouse", "notebook", "chair", "tv", "light", "sofa", "plate", "screem", "aleloui")
for vogal in lotWords:
if("a" in vogal and "e" and vogal and "i" in vogal and "o" in vogal and "u" in vogal):
a = vogal.find("a")
e = vogal.find("e")
i = vogal.find("i")
o = vogal.find("o")
u = vogal.find("u")
print(f"In phrase {vogal}, we have the vowels {vogal[a]}, {vogal[e]}, {vogal[i]}, {vogal[o]}, {vogal[u]}")
if ("a" in vogal and "e" in vogal and "i" in vogal and "o" in vogal):
a = vogal.find("a")
e = vogal.find("e")
i = vogal.find("i")
o = vogal.find("o")
print(f"In phrase {vogal}, we have the vowels {vogal[a]}, {vogal[e]}, {vogal[i]}, {vogal[o]}")
if ("a" in vogal and "e" in vogal and "i" in vogal):
a = vogal.find("a")
e = vogal.find("e")
i = vogal.find("i")
print(f"In phrase {vogal}, we have the vowels {vogal[a]}, {vogal[e]}, {vogal[i]}")
if ("a" in vogal and "e" in vogal):
a = vogal.find("a")
e = vogal.find("e")
print(f"In phrase {vogal}, we have the vowels {vogal[a]}, {vogal[e]}")
if ("a" in vogal):
a = vogal.find("a")
print(f"In phrase {vogal}, we have the vowels {vogal[a]}")
if ("e" in vogal):
e = vogal.find("e")
print(f"In phrase {vogal}, we have the vowels {vogal[e]}")
if ("i" in vogal):
i = vogal.find("i")
print(f"In phrase {vogal}, we have the vowels {vogal[i]}")
if ("o" in vogal):
o = vogal.find("o")
print(f"In phrase {vogal}, we have the vowels {vogal[o]}")
if ("u" in vogal):
u = vogal.find("u")
print(f"In phrase {vogal}, we have the vowels {vogal[u]}")
# else:
# print("This is not in 'aeiou'")
# print(vogal)'''
# SOLUTION FROM GUANABARA
'''lotWords = ("rice", "mouse", "notebook", "chair", "tv", "light", "sofa", "plate", "screem", "aleloui")
for vowels in lotWords:
print(f"\nIn the phrase {vowels.upper()} we have: ", end="")
for letter in vowels:
if(letter.lower() in "aeiou"):
print(letter, end=" ")'''
# CLASS 17
# num = (2, 4, 8, 1, 3)
# num[2] = 4 # tuplas são imutáveis
# print(num)
'''
num = [2, 4, 8, 1, 3]
num[2] = 0
# num = 5 # receber total
# print(num)
num.append(6)
num.sort()
num.sort(reverse=True)
num.insert(5, 10)
num.pop(4)
num.insert(4, 4)
if(1 in num):
num.remove(4)
else:
print("não encontrei o valore 1!")
print(num)
print(f"Essa lista tem {len(num)} elementos!")'''
'''valores = list()
# valores.append(4)
# valores.append(9)
# valores.append(2)
# print(valores)
for count in range(0, 6):
valores.append(int(input("Enter with a number: ")))
for c, v in enumerate(valores):
print(f"Na posição {c}, encontrei o valor {v}!")
print("Cheguei ao final da lista!")'''
'''a = [1, 7, 5, 3]
# b = a # Cria uma ligação entre as listas
b = a[:] # Lista B cria uma cópia de lista A
b[2] = 9
print(f"Lista A: {a}")
print(f"Lista B: {b}")'''
# CHALLENGE 78
# Faça um programa que leia 5 valores numéricos e guarde-os em uma lista.
# No final, mostre qual foi o maior e o menor valor digitado e as suas respectivas posições na lista.
'''valNum = rankMax = rankMin = []
count = 0
for pos, read in enumerate(range(0, 5)):
count += 1
a = int(input("Enter with the number for the position {}: ".format(count)))
valNum.append(a)
if(count == 1):
rankMax.append(pos)
rankMin.append(pos)
maior = menor = a
if(a > maior):
maior = a
if(a > )
rankMax.remove(max(rankMax))
rankMax.append(pos)
if(a < menor):
menor = a
rankMin.append(pos)
print(f"You entered with the values: {valNum}")
print(f"O biggest value entered was {max(valNum)}, in the positions {rankMax}")
print(f"O lowest value entered was {min(valNum)}, in the positions {rankMin}")'''
# ////////////////////////////////////////////////////////
# Done
'''valNum = []
a = []
b = []
# count = max = min = rankMax = rankMin = a = 0
count = 0
for pos, read in enumerate(range(0, 20)):
add = int(input("Enter with the number for the position {}: ".format(pos+1)))
count += 1
if(count == 1):
a.append(pos+1)
b.append(pos+1)
maior = menor = add
if(add > maior):
maior = add
if(add in valNum):
if(add > max(valNum)):
del(a[:])
a.append(pos+1)
if(add == max(valNum)):
a.append(pos+1)
# else:
# continue
else:
if(add > max(valNum)):
del(a[:])
a.append(pos+1)
if(add == max(valNum)):
a.append(pos+1)
# else:
# continue [5, 9, 15, 20, 45, 45, 12, 15, 16, 79, 15, 45, 7, 5, 5, 6, 45, 79, 79, 45, 5]
if(add < menor):
menor = add
if(add in valNum):
if(add < min(valNum)):
del(b[:])
b.append(pos+1)
if(add == min(valNum)):
b.append(pos+1)
# else:
# continue
else:
if(add < min(valNum)):
del(b[:])
b.append(pos+1)
if(add == min(valNum)):
b.append(pos+1)
# else:
# continue
else:
if(add in valNum):
if(add == max(valNum)):
a.append(pos+1)
else:
if(add == min(valNum)):
b.append(pos+1)
valNum.append(add)
# print(f"Max A {max(a)}")
# print(f"Min B {min(b)}")
print(f"You entered with the values: {valNum}")
print(f"The biggest value entered was {max(valNum)}, in the positions {a}")
print(f"The lowest value entered was {min(valNum)}, in the positions {b}")'''
# //////////////////////////////////////////////////////////////////////////////////
# SOLUTION FROM GUANABARA
'''lista = list()
bigger = lower = 0
# for rank, value in enumerate(range(0, int(input("Enter with a number: ")))):
for value in range(0, 5):
# print(" First", value)
lista.append(int(input("Enter with a number: ")))
# print("Second", value)
if(value == 0):
bigger = lower = lista[value]
else:
if(lista[value] > bigger):
bigger = lista[value]
if(lista[value] < lower):
lower = lista[value]
# print(lista[value])
print(lista)
print(f"The biggest numbers was {bigger}, And they are in the posotion ", end=" ")
for pos, valueB in enumerate(lista):
if(valueB == bigger):
print(f"{pos}", end="...")
print(f"\nThe lowest number entered was: {lower}, and are in the position: ", end="")
for pos, valueB in enumerate(lista):
if(valueB == lower):
print(f"{pos}", end="...")'''
# CHALLENGE 79
# Crie um programa onde o usuário possa digitar vários valores numéricos e cadastre-os em uma lista.
# Caso o número já exista lá dentro, ele não será adicionado. No final, serão exibidos todos os valores únicos digitados, em ordem crescente.
'''list = []
while True:
adicionar = int(input("Enter with a number: "))
if(adicionar in list):
print("Este número já existe na lista, não vou adicionar!")
else:
list.append(adicionar)
print(f"O número {adicionar} foi adicionado com sucesso!")
stop = str(input("Do you want keep up ? [Y / N]: "))
if(stop[0].upper() == "N"):
break
list.sort()
print(f"Você digitou os números: {list}")'''
# CHALLENGE 80
# Crie um programa onde o usuário possa digitar cinco valores numéricos e cadastre-os em uma lista,
# já na posição correta de inserção (sem usar o sort()). No final, mostre a lista ordenada na tela.
'''lista = []
for b, a in enumerate(range(0, 5)):
add = int(input("Enter with a number: "))
if(add not in lista):
for c in lista:
if(c < min(lista)):
lista.append(add)
print(f"{add} foi adicionado na posição {b}")
if(c > max(lista)):
lista.append(add)
print(f"{add} foi adicionado na posição {b}")
else:
print(f"Você cadastrou os números {lista}")'''
# //////////////////////////// 45 47 44 49 16 50 47 46 49 47
'''lista = list()
count = 0
for b, a in enumerate(range(0, 10)):
add = int(input("Enter with a number: "))
# if(add in lista):
# for c in lista:
# count += 1
# if(c == add):
# lista.insert(lista.index(c)+count, add)
# print(f"{add} foi adicionado na posição {lista.index(c)+count}")
# break
if(add not in lista):
for c in lista:
count += 1
if(add > max(lista)):
count += 1
lista.insert((lista.index(max(lista)))+1, add)
print(f"{add} foi adicionado na última posição ({lista.index(max(lista))})º!")
break
elif(add < min(lista)):
count += 1
lista.insert((lista.index(min(lista))), add)
print(f"{add} foi adicionado na primeira posição ({lista.index(min(lista))})º!")
break
else:
if(add == c):
count += 1
lista.insert(lista.index(c), add)
print(f"{add} foi adicionado na posição {lista.index(c)}")
break
if(count <= 0):
lista.append(add)
print(f"{add} foi adicionado na última posição!")
else:
if(add not in lista):
# count += 1
# for c in lista:
if(add > lista[-1]):
lista.insert(lista.index(lista[-1])+1, add)
print(f"{add} foi adicionado na posição {lista.index(lista[-1])+1}")
else:
pos = 0
while(pos < len(lista)):
if(add <= lista[pos]):
lista.insert(pos, add)
break
pos += 1
print(f"{add} foi adicionado na posição {lista.index(add)}")
# z = lista.count(add)
# if(z > 1):
# del(lista[1])
# break
# if(count <= 0): # 45 25 16 49 44 /// 16, 47, 47, 44, 45, 47, 46, 47, 49, 50] //// 45 47 44 49 16 50 47 46 49 47
# lista.append(add)
# print(f"{add} foi adicionado na última posição!")
# break
else:
if(add in lista):
# count += 1
for c in lista:
if(c == add):
lista.insert(lista.index(c), add)
print(f"{add} foi adicionado na posição {lista.index(c)+1}")
break
# else:
# lista.append(add)
print("="*60)
print(f"Você cadastrou, em ordem, os números: {lista}")
print(len(lista))'''
# CHALLENGE 81
# Crie um programa que vai ler vários números e colocar em uma lista. Depois disso, mostre:
# A) Quantos números foram digitados. B) A lista de valores, ordenada de forma decrescente. C) Se o valor 5 foi digitado e está ou não na lista.
'''cadastro = []
count = 0
while True:
cadastro.append(int(input("Enter with a number: ")))
count += 1
user = str(input("Wolud like to continue ? [S / N]: ")).strip().upper()[0]
if(user == "N"):
break
print("="*50)
print(f"The list entered with the numbers is: {cadastro}")
print("="*50)
print(f"The total of elements entered were: {count}")
print("="*50)
if(5 in cadastro):
print(f"The number '5' is in the list {cadastro}, in the position {cadastro.index(5)}")
print("The number '5' logically was entered")
else:
print(f"The number '5' is not in lista: {cadastro}")
print("="*50)
cadastro.sort(reverse=True)
print(f"The numbers inserted in position decreasing is: {cadastro}")'''
# CHALLENGE 82
# Crie um programa que vai ler vários números e colocar em uma lista.
# Depois disso, crie duas listas extras que vão conter apenas os valores pares e os valores ímpares digitados, respectivamente.
# Ao final, mostre o conteúdo das três listas geradas.
'''lista1 = []
listaEven = []
listaOdd = []
evenCount = 0
oddCount = 0
while True:
lista1.append(int(input("Enter with a number: ")))
contiOrBreak = str(input("Would like to continue ? [Y / N]: ")).strip().upper()[0]
if (contiOrBreak == "N"):
break
for even in lista1:
if(even % 2 == 0):
listaEven.append(even)
evenCount += 1
else:
listaOdd.append(even)
oddCount += 1
print(f"The numbers entered in the list were: {lista1}")
print(f"The numbers even entered were: {listaEven} and they are at totally: {evenCount}")
print(f"The numbers odd entered were: {listaOdd} and they are at totally: {oddCount}")'''
# CHALLENGE 83
# Crie um programa que vai ler vários números e colocar em uma lista.
# Depois disso, crie duas listas extras que vão conter apenas os valores pares e os valores ímpares digitados, respectivamente.
# Ao final, mostre o conteúdo das três listas geradas.
'''express = list(str(input("Enter with the express: ")))
# print(express[-1])
# print(express)
# print(len(express))
# print("(" in express)
# print(express.count("("))
# for together in express:
# if(express[0] == ")"):
# print("Express is not allowed!")
if(express.count("(") == express.count(")") and express[-1] != "(" and express[0] != ")"):
print("Express is allowed!")
# elif(str(express)):
# if(express[-1] == "("):
# print("Express is not allowed!")
else:
if(express[0] == ")" or express[-1] == "(" or express.count("(") != express.count(")")):
print("Express is not allowed!")
# print(len(express))
# print("".join(express))
# a = []
# for to in express:
# print(to)
print(f"The Express used was '{''.join(express)}'")'''
'''exp = str(input('Digite a expressão: '))
print('A expressão está correta!' if exp.count('(') == exp.count(')') and exp[0] != ")" and exp[-1] != "(" else 'A expressão está errada!')'''
# SOLUTION FROM GUANABARA
'''express = list(str(input("Enter with the express: ")))
pilha = list()
for sim in express:
if(sim == "("):
pilha.append("(")
elif(sim == ")"):
if(len(pilha) > 0):
pilha.pop()
else:
pilha.append(")")
break
if(len(pilha) == 0):
print("A sua expressão está certa!")
else:
print("A sua expressão não está certa!")'''
# CLASS 18
'''teste = list()
teste.append("Johnny")
teste.append(26)
print(teste)
galera = list()
galera.append(teste[:])
print(galera)
teste[0] = "Jorge"
teste[1] = 30
print(galera)
galera.append(teste[:])
print(galera)'''
'''galera = [["Danilo", 40], ["Alana", 25], ["Jose", 26], ["João", 18]]
# print(galera[3][0])
for p in galera:
# print(p[0][1])
print(f"{p[0]}, tem {p[1]} anos de idade")'''
'''galera = list()
dados = list()
totmaoir = totmenor = 0
for c in range(0, 3):
dados.append(str(input("Digite o nome: ")))
dados.append(int(input("Digite idade: ")))
galera.append(dados[:])
dados.clear()
# print(galera)
for p in galera:
if(p[1] >= 21):
print(f"{p[0]}, é maior de idade!")
totmaoir += 1
else:
print(f"{p[0]}, é menor de idade!")
totmenor += 1
print(f"O total de maiores de idade é {totmaoir} e de menor é {totmenor}")'''
# CHALLENGE 84
# Faça um programa que leia nome e peso de várias pessoas, guardando tudo em uma lista. No final, mostre:
# A) Quantas pessoas foram cadastradas, B) Uma listagem com as pessoas mais pesadas e C) Uma listagem com as pessoas mais leves.
'''nome = list()
dada = list()
heaviestLi = list()
lightestLi = list()
person = 0
while True:
nome.append(str(input("What is your system: ")))
nome.append(float(input("How much weight are you: ")))
contOrBrk = str(input("Would like to continue [Y / N] ? "))
dada.append(nome[:])
nome.clear()
if(contOrBrk[0].upper().strip() == "N"):
break
for p in dada:
if(p[0] == p[0]):
person += 1
nome.append(p[0])
heaviest = dada[0][1]
lighter = dada[0][1]
count = 0
for w in dada:
if(w[1] >= heaviest):
# print(f"{w[0]} is the most heaviest!")
if(w[1] == heaviest):
heaviestLi.append(w[0])
if(w[1] > heaviest):
heaviest = w[1]
heaviestLi.clear()
heaviestLi.append(w[0])
if(w[1] <= lighter):
# print(f"{w[0]} is the most lightest!")
if(w[1] == lighter):
lightestLi.append(w[0])
if(w[1] < lighter):
lighter = w[1]
lightestLi.clear()
lightestLi.append(w[0])
count += 1
print(f"The list you have entered was: {dada}")
print(f"The total of people register was: {person}")
print(f"They are: {nome}")
print(f"The people who is the most heaviest is {heaviestLi}, with {heaviest}Kg!")
print(f"The people who is the most lightest is {lightestLi}, with {lighter}Kg!")'''
# //////////////////////////////////////////////////////////////////////////////////////
# SOLUTION FROM GUANABARA
'''temp = []
princ = []
mai = men = 0
while True:
temp.append(str(input("Nome: ")))
temp.append(float(input("Peso: ")))
if(len(princ) == 0):
mai = men = temp[1]
else:
if(temp[1] > mai):
mai = temp[1]
if(temp[1] < men):
men = temp[1]
princ.append(temp[:])
temp.clear()
resp = str(input("Quer continuar? [S / N] "))
if(resp in "Nn"):
break
print("-="*50)
# print(f"Os dados foram {princ}")
print(f"Ao todo, você cadastrou {len(princ)} pessoas")
print(f"O menor peso foi de {men}Kg. Peso de ", end="")
for p in princ:
if(p[1] == men):
print(f"[{p[0]}]", end=" ")
print()
print(f"O maior peso foi de {mai}Kg. Peso de: ", end=" ")
for p in princ:
if(p[1] == mai):
print(f"[{p[0]}]", end=" ")'''
# CHALLENGE 85
# Crie um programa onde o usuário possa digitar sete valores numéricos e cadastre-os em uma lista única
# que mantenha separados os valores pares e ímpares. No final, mostre os valores pares e ímpares em ordem crescente.
'''numeros = [[], []]
for c in range(1, 7+1):
user = int(input(f"Digite o {c}º valor: "))
if(user % 2 == 0):
numeros[0].append(user)
if(user % 2 == 1):
numeros[1].append(user)
print("-=" * 50)
numeros[0].sort()
numeros[1].sort()
# print(numeros)
print(f"Os valore pare cadastrados são: {numeros[0]}")
print(f"Os valores impares cadastrados são: {numeros[1]}")'''
# ////////////////////////////////////////////////////////
# ANOTHER SOLUTION
'''lista_de_numeros = []
for c in range(1, 8):
lista_de_numeros.append(int(input(f'Digite o {c}° valor: ')))
lista_de_numeros.sort()
print('-=' * 40)
print(f'Os valores pares digitados foram: ', end='')
for n in lista_de_numeros:
if n % 2 == 0:
print(f'{n} ', end='')
print(f'\nOs valores impares digitados foram: ', end='')
for n in lista_de_numeros:
if n % 2 != 0:
print(f'{n} ', end='')'''
# for n in numeros:
# # if(n % 2 == 0):
# numeros.append([n[numeros]])
# if(n % 2 == 1):
# numeros.append([n][numeros])
# print(numeros)
'''val = list()
evenAndOdd = list()
for rank, c in enumerate(range(0, 7)):
user = int(input(f"Enter with the {rank+1}º. value: "))
val.append([user][0])
# print(val)
for d in val:
if(d % 2 == 0):
evenAndOdd.append([[1], [0]])
else:
if(d % 2 == 1):
evenAndOdd.append([[0], [1]])
print(evenAndOdd)'''
# print(val)
# for a in val:
# if(a % 2 == 0):
# evenAndOdd.append()
# else:
# evenAndOdd.append([0][0])
# # j = evenAndOdd[0][1]
# print(evenAndOdd)
# print(j)
# CHALLENGE 86
# Crie um programa que declare uma matriz de dimensão 3×3 e preencha com valores lidos pelo teclado.
# No final, mostre a matriz na tela, com a formatação correta.
'''a = list()
count = 0
for c in range(0, 3):
for x in range(0,3):
if(count < 3):
a.append(int(input("Digite o primeiro valor para [{}, {}]: ".format(c, x))))
count += 1
count = 0
for y in range(3, 6):
if(count > 2 and count < 6):
a.append(int(input("Digite o primeiro valor para [{}, {}]: ".format(count, y))))
count += 1
count = 0
for z in range(7, 9):
if(count > 5 and count < 10):
a.append(int(input("Digite o primeiro valor para [{}, {}]: ".format(count+c, z))))
count += 1
count = 0
for d in a:
if(count < 3):
print("[ {} ]".format(d), end="")
count += 1
print()
count = 0
for d in a:
if(count > 2 and count < 6):
print("[ {} ]".format(d) , end="")
count += 1
print()
count = 0
for d in a:
if(count > 5):
print("[ {} ]".format(d) , end="")
count += 1'''
# SOLUTION FROM GUANABARA
'''matriz = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for l in range(0, 3):
for c in range(0, 3):
matriz[l][c] = int(input(f"Digite um valor para: [{l}, {c}]: "))
print(matriz)
for numero in matriz:
for numero1 in numero:
print(f"[{numero1:^5}]", end=" ")
print()'''
# CHALLENGE 87
# Aprimore o desafio anterior, mostrando no final.
# A) A soma de todos os valores pares digitados. B) A soma dos valores da terceira coluna. C) O maior valor da segunda linha.
'''a = list()
count = 0
somaPar = 0
tercCol = 0
maior = 0
for c in range(0, 3):
for x in range(0,3):
if(count < 3):
user = int(input("Digite o primeiro valor para [{}, {}]: ".format(c, x)))
if(user % 2 == 0):
somaPar += user
if(count == 2):
tercCol += user
if(c == 1):
maior = user
if(count > 3):
if(user > maior):
maior = user
a.append(user)
count += 1
count = 0
# for y in range(3, 6):
# if(count > 2 and count < 6):
# user = int(input("Digite o primeiro valor para [{}, {}]: ".format(count, y)))
# if(user % 2 == 0):
# somaPar += user
# if(count == 5):
# tercCol += user
# if(count == 3):
# maior = user
# if(count > 3):
# if(user > maior):
# maior = user
# a.append(user)
# count += 1
# count = 0
# for z in range(7, 9):
# if(count > 5 and count < 10):
# user = int(input("Digite o primeiro valor para [{}, {}]: ".format(count, y)))
# if(user % 2 == 0):
# somaPar += user
# if (count == 9):
# tercCol += user
# if (count == 3):
# maior = user
# if(count > 3):
# if(user > maior):
# maior = user
# a.append(user)
# count += 1
count = 0
for d in a:
if(count < 3):
print("[ {:^5} ]".format(d), end="")