Skip to content

Update word replacement.py, quiz.py, passwordgenerator.py and basic_calculator.py #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions basic calculator.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
def add(a, b):
answer = a + b
print(str(a) + " + " + str( b) + " = " + str(answer) + "\n")
print(str(a) + " + " + str(b) + " = " + str(answer) + "\n")

def sub(a, b):
answer = a - b
print(str(a) + " - " + str(b ) + " = " + str(answer) + "\n")
def mul(a, b):
answer = a*b
print(str(a) + " - " + str(b) + " = " + str(answer) + "\n")

def mul(a,b):
answer = a * b
print(str(a) + " * " + str(b) + " = " + str(answer) + "\n")
def div(a, b):

def div(a,b):
answer = a / b
print(str(a) + " / " + str(b) + " = " + str(answer) + "\n")

def pow(a,b):
answer = a ** b
print(str(a) + " ** " + str(b) + " = " + str(answer) + "\n")

def modulo(a,b):
answer = a % b
print(str(a) + " % " + str(b) + " = " + str(answer) + "\n")

while True:
print("Choose operator you want! Can Just Input Integer Number")
print("A. Addition")
print("B. Subtraction")
print("B. Substraction")
print("C. Multiplication")
print("D. Division")
print("E. Exit")
choice = input("input your choice: ")
print("E. Pow")
print("F. Modulo")
print("G. Exit")

choice = input("Input Your Choice: ")

if choice == "a" or choice == "A":
print("Addition")
a = int(input("input first number: "))
b = int(input("input second number: "))
add(a, b)
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
add(a,b)
elif choice == "b" or choice == "B":
print("Subtraction")
a = int(input("input first number:"))
b = int(input("input second number: "))
sub(a, b)
print("Substraction")
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
sub(a,b)
elif choice == "c" or choice == "C":
print("Multiplication")
a = int(input("input first number:"))
b = int(input("input second number: "))
mul(a, b)
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
mul(a,b)
elif choice == "d" or choice == "D":
print("Division" )
a = int(input("input first number:"))
b = int(input("input second number: "))
div(a, b)
print("Division")
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
div(a,b)
elif choice == "e" or choice == "E":
print("program ended")
print("Pow")
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
pow(a,b)
elif choice == "f" or choice == "F":
print("Modulo")
a = float(input("Input Number Here: "))
b = float(input("Input Number Here: "))
modulo(a,b)
elif choice == "g" or choice == "G":
print("Game Ended")
quit()

106 changes: 61 additions & 45 deletions quiz program.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
quiz = {
"question1": {
"question": "What is the capital of France?",
"answer": "Paris"
},
"question2": {
"question": "What is the capital of Germany?",
"answer": "Berlin"
},
"question3": {
"question": "What is the capital of Italy?",
"answer": "Rome"
},
"question4": {
"question": "What is the capital of Spain?",
"answer": "Madrid"
},"question5": {
"question": "What is the capital of Portugal?",
"answer": "Lisbon"
},"question6": {
"question": "What is the capital of Switzerland?",
"answer": "Bern"
},"question7": {
"question": "What is the capital of Austria?",
"answer": "Vienna"
},
}
def ask():
quiz = {
"question1" : {
"question": "What is the capital of France?",
"answer": "Paris"
},
"question2" : {
"question": "What is the capital of Germany?",
"answer": "Berlin"
},
"question3" : {
"question": "What is the capital of Italy?",
"answer": "Roma"
},
"question4" : {
"question": "What is the capital of Spain?",
"answer": "Madrid"
},
"question5" : {
"question": "What is the capital of Portugal?",
"answer": "Lisbon"
},
"question6" : {
"question": "What is the capital of Switzerland?",
"answer": "Bern"
},
"question7" : {
"question": "What is the capital of Austria?",
"answer": "Vienna"
},

}

score = 0
score = 0

for key, value in quiz.items():
print(value[' question' ])
answer = input("Answer? ")
for key, value in quiz.items():
print(value['question'])
answer = input("Answer? ")

if answer.lower() == value['answer'].lower():
print('Correct')
score = score + 1
print("Your Score: " + str(score))
print("")
print("")
else:
print("Wrong!")
print("The Answer is : " + value['answer'])
print("Your Score is : " + str(score))
print("")
print("")

if answer.lower() == value[ 'answer'] . lower():
print('Correct')
score = score + 1
print("Your score is: " + str(score))
print("")
print("")
else:
print("Wrong!")
print("The answer is : " + value[ ' answer'])
print("Your score is: " + str(score))
print("")
print("")
print("You got " + str(score) + " out of 7 question correctly")
print("Your percentage is " + str(int(score/7 * 100)) + " %")

print("You got " + str(score) + " out of 7 questions correctly")
print("Your percentage is " + str(int(score/7 * 100)) + "%")

while True:
replay = input("Still Wanna Play ? (y/n) ")
if replay == "Y" or replay == "y":
ask()
else:
quit()

print("Welcome to Our Quiz!!")
ask()
38 changes: 20 additions & 18 deletions random password generator.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import string
import random

characters = list(string.ascii_letters + string.digits + " !@#$%^&*()")
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")

def generate_password():
password_length = int(input("How long would you like your password to be? "))

random.shuffle(characters)

password = []

for x in range(password_length):
password.append(random.choice(characters))

random.shuffle(password)

password = "" .join(password)
print(password)

option = input("Do you want to generate a password? (Yes/No): ")
random.shuffle(password)

if option == "Yes":
generate_password()
elif option == "No":
print("Program ended")
quit()
else:
print("Invalid input, please input Yes or No")
quit()
password = "".join(password)
print(password)
option = input("Do you still wanna generate a password? (y/n) ") # made option for replay game again
if option == 'Y' or option == 'y':
generate_password()
elif option == 'N' or option == 'n':
print('Program Ended')
quit()
else:
print("Invalid input, please input Y or N")
quit()


print('Welcome to Your Password Generator')
generate_password()
9 changes: 6 additions & 3 deletions word replacement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
def replace_word():
str = "hi guys, i am tomi, and hi hi hi hi"
word_to_replace = input("Enter the word to replace: ")
str = input("Words i wanna type: ") #made word with input from user
word_to_replace = input("Enter The Word to replace: ")
word_replacement = input("Enter the word replacement: ")
print(str.replace(word_to_replace, word_replacement))

back = input("Still wanna play this game : (y/n) ? ")
if back == 'y' or back == 'Y': #made replay game if input = y or Y
return replace_word()

replace_word()