-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGame.py
More file actions
92 lines (61 loc) · 1.83 KB
/
Game.py
File metadata and controls
92 lines (61 loc) · 1.83 KB
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
'''
Game:
- welcome message to user.
- show games.
- user can play : game number
- option to exit.
- ask play again.
Games:
- sentence no duplicate.
-names ---> list[count]
- x, y: 1 ---> 100
'''
class Game:
def __init__(self):
print(''' Welcome to our Game:
1- Sentence No Duplicate.
2- Names List Count.
3- Divided By.
4- to exit.
''')
user_choice = int(input('Enter Game Number: '))
if user_choice == 1:
sentence = input('Enter Sentence: ')
self.no_duplicate(sentence)
elif user_choice == 2:
names = eval(input('Enter Names : '))
self.names_count(names)
elif user_choice == 3:
first_number = int(input('Enter First Number: '))
second_number = int(input('Enter Second Number: '))
self.divided_by(first_number, second_number)
elif user_choice == 4:
print('Goodbey ...')
return
else:
print('please enter numbers between 1:3')
def no_duplicate(self, sentence):
words = sentence.split(' ')
new_words = []
for w in words:
if w in new_words:
continue
else:
new_words.append(w)
new_sentence = ' '.join(new_words)
print(new_sentence)
def names_count(self, names):
count = []
for n in names:
count.append(len(n))
print(count)
def divided_by(self, x, y):
result = []
for n in range(1, 101):
if n%x == 0 and n%y == 0:
result.append(n)
print(result)
g1 = Game()
#no_duplicate('my name is is is alex')
#names_count(['alex', 'anna', 'emma'])
#divided_by(5,6)