-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.py
131 lines (105 loc) · 3.02 KB
/
function.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
# function for guessing number
import random
from random import randint
import pyttsx3
import sentences
engine = pyttsx3.init()
# rate
rate = engine.getProperty("rate")
engine.setProperty("rate", 113)
# volume
volume = engine.getProperty("volume")
engine.setProperty("volume", 1.0)
# voice
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
# function of speak
def speak(text):
engine.say(text)
engine.runAndWait()
def guessinggame():
computer = random.randint(1, 10)
player = int(input("enter a number between 1 and 10 >> "))
if player == computer:
print("you win")
speak("you win")
else:
print("you are a looser :)")
speak("you are looser :)")
# function for rock paper scissors
def rockpaperscissors():
t = ["rock", "paper", "scissors"]
computer = t[randint(0, 2)]
player = input("rock, paper, scissors >>> ")
if player == computer:
speak("Tie")
print("Tie")
print(computer)
speak(computer)
elif player == "rock":
if computer == "scissors":
speak("You win")
print("You win")
print(computer)
speak(computer)
else:
speak("You loose, :) ")
print("You loose, :) ")
print(computer)
speak(computer)
elif player == "paper":
if computer == "rock":
speak("You win")
print("You win")
print(computer)
speak(computer)
else:
speak("You loose, :) ")
print("You loose, :) ")
print(computer)
speak(computer)
elif player == "scissors":
if computer == "paper":
speak("You win")
print("You win")
print(computer)
speak(computer)
else:
speak("You loose, :) ")
print("You loose, :) ")
print(computer)
speak(computer)
else:
speak("Not valid")
print("Not valid")
computer = t[randint(0, 2)]
# function for calculator
def calculator():
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
for calcul in sentences.calcul:
print(calcul)
choice = input("enter choice(1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number : "))
num2 = float(input("Enter second number : "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
if num2 == 0:
print("the division can not be done")
else:
print(num1, "/", num2, "=", divide(num1, num2))
else:
speak("invalid input")
print("Invalid Input")