-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tugas TA 28 September.py
91 lines (77 loc) · 2.26 KB
/
Tugas TA 28 September.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
#NUMBER 1
def last_name():
print("Enter name: ")
name = str(input())
#Splitting the name and replacing "-" with an empty space
words = name.replace('-',' ').split()
#Take the first alphabet from a word
sen = [word[0] for word in words]
print ("".join(sen).upper())
last_name()
#NUMBER 2
list = []
dict = {}
count=0
while count<10:
#For the user to enter exactly 10 numbers
num=int(input("Enter number: "))
#Adding the input numbers to the list
list.append(num)
count+=1
for i in list: #For every number
#Calculating the remainder
mod=i%42
dict[mod]=0
# Remainders are in the dictionary
print(len(dict.keys()))
#NUMBER 3
n = int(input("Enter number of stones: "))
while n > 0:
#Alice takes 2 consecutive stones every turn
a = print("Alice takes 2 ")
stone = n - 2
if stone < 0:
print ("0 stones left")
break
if stone % 2 and stone > 0:
#if the stones are odd, Alice wins
print("\n""->""Alice")
print ("\n",stone, "stone(s) left")
else:
#if the stones are even, Bob wins
print("\n""->""Bob")
print("\n", stone, "stone(s) left")
if stone == 1:
print("\n" "->""Alice")
break
stone = stone - 2
#Bob takes 2 consecutive stones every turn
b = print("Bob takes 2 ")
if stone % 2 and stone != 0:
print ("\n""->""Alice")
print("\n",stone, "stone(s) left")
else:
print("\n""->""Bob")
print("\n",stone, "stone(s) left")
n = stone
continue
#NUMBER 4
x=input("Movement Pattern: ")
list=['ball','empty','empty2']
#The list contains the three cups. "ball" is the cup with the ball.
a=list.index('ball')
b=list.index('empty')
c=list.index('empty2')
for i in x:
if i =='A' or i == "a": #Switches left cup and middle cup (ball in left cup)
list[a],list[b]=list[b],list[a]
elif i =='B' or i == "b": #Switches middle cup and right cup
list[b],list[c]=list[c],list[b]
elif i == "C" or i == "c": #Switches left cup with right cup
list[a],list[c]=list[c],list[a]
if list.index('ball')==0: #If the ball is on the left
print("1")
elif list.index('ball')==1: #If the ball is in on the middle
print("2")
else: # If the ball is on the right
print("3")