Repository navigation
Expand file tree
/
Copy pathhomework1
More file actions
118 lines (81 loc) · 2.96 KB
/
Copy pathhomework1
File metadata and controls
118 lines (81 loc) · 2.96 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
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
# Q-1
# A-
grad_std = ["maiky","jack","mahran","selena","christena"]
name = input("inter student name: ")
if name in grad_std:
print("the student " + name + " is graduated")
else :
print("the student " + name + "is not graduated")
# Q-1
# B-
List = []
for num in range(1,1001,1):
if num % 2 == 1:
List.append(num)
print (List)
# Q-1
# C-
L = ['Network','Math','Programming','Physics','Music']
char='P'
def find_p(List,char):
for i in List:
if char in i:
print(i)
find_p(L,'P')
# Q-1
# D-
d={1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0}
for key, value in d.items():
d[key]=value*value
print(d)
# Q-2
binary=[]
decimal = int(input ("inter your decimal number: "))
while(decimal>0):
if decimal % 2 == 0:
binary.append(0)
else:
binary.append(1)
decimal //= 2
binary.reverse()
print("the equivalent binary number is: " + str(binary))
# Q-3
def new_file(file_name,ques_ans):
Write = open(file_name,"w")
ques_ans = [line+"\n" for line in ques_ans]
Write.writelines(ques_ans)
Write.close()
quest_list = ["Q1: What is the author name of the book 'Age Of Renascence'?:;Abn-alnafes",
"Q2: What is the author name of the book 'The girl on the train'?:;Paola Hokens",
"Q3: What is the author name of the book 'In furiously Happy'?:;Jeny Loson",
"Q4: What is the author name of the book 'The library at mount cha'?:;Paola Hokens",
"Q5: What is the author name of the book 'Stranger than we can imagine'?:;John Higes",
"Q6: What is the author name of the book 'Humans of Newyork'?:;Brandon Stanton",
"Q7: What is the author name of the book 'The girl on the train'?:;Paola Hokens",
"Q8: What is the author name of the book 'I take you'?:; Eliza Kennedy",
"Q9: What is the author name of the book 'Our solus at Night'?:;Kint haroph",
"Q10: What is the author name of the book 'Nimona'?:;Noele Stevenson"]
new_file("Ques_Ans_file.text" , quest_list)
def work_file(file_name):
Read = open(file_name , "r")
list_Read = [line.rstrip().split(";") for line in Read]
return list_Read
Read.close
quest_list = work_file("Ques_Ans_file.text")
user_name = input("enter your name: ")
print("Hello and welcom to my game puzzle: )")
user_name_file = open("user_result.text", "w")
user_name_file.write(user_name)
user_name_file = open("user_result.text", "a")
Score = 0
for i in range(0,10):
ans = input(quest_list[i][0])
if ans == quest_list[i][1]:
Score += 1
user_name_file.write("your anwser is correct!!".format(quest_list[i][0] , quest_list[i][1]))
else:
user_name_file.write("your anwser is Wrong!! and the correcy anwser is: ".format(quest_list[i][0] , quest_list[i][1]))
user_name_file.write("your final score is: ".format(Score))
user_name_file.close()
print(open("user_result.text", "r").read())
user_name_file.close()