-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_practiceFile.py
More file actions
62 lines (41 loc) · 1.25 KB
/
20_practiceFile.py
File metadata and controls
62 lines (41 loc) · 1.25 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
# Q1. Found the word from practice txt file
# f = open("practice.txt")
# data = f.read()
# if("Twinkle" in data):
# print("Found")
# else:
# print("Not Found")
# f.close()
# Q2. Check the highscore
# import random
# def game():
# print("You are playing the game")
# score = random.randint(1,69)
# with open("hiscore.txt") as f:
# hiscore = f.read()
# if(hiscore != ""):
# hiscore = int(hiscore)
# else:
# hiscore = 0
# print(f"your score: {score}")
# if(score > hiscore or hiscore == ""):
# with open("hiscore.txt" , "w") as f:
# f.write(str(score))
# return score
# game()
# Q3. Program to write table from 2 to 20
# def generateTable(n):
# table = ""
# for i in range(1,11):
# table+= f"{n} X {i} = {n*i}\n"
# with open(f"table/table_{n}.txt" , "w") as f:
# f.write(table)
# for i in range(1,21):
# generateTable(i)
# Q4. Replace the word "Rishav" with "Batman"
# word = "Rishav"
# with open("replace.txt" , "r") as f:
# data = f.read()
# newData = data.replace(word , "Batman")
# with open("replace.txt" , "w") as f:
# data = f.write(newData)