diff --git a/Contributors.html b/Contributors.html index d2f4a02641..1bdfe15816 100644 --- a/Contributors.html +++ b/Contributors.html @@ -396,7 +396,8 @@ Sara MC Theressa - Naushad Alam + Naushad Alam + Ankita Mandal diff --git a/Program's_Contributed_By_Contributors/Python_Programs/Calculator.py b/Program's_Contributed_By_Contributors/Python_Programs/Calculator.py new file mode 100644 index 0000000000..5b42972851 --- /dev/null +++ b/Program's_Contributed_By_Contributors/Python_Programs/Calculator.py @@ -0,0 +1,68 @@ +""" Calculator +---------------------------------------- +""" +def addition (): + print("Addition") + n = float(input("Enter the number: ")) + t = 0 //Total number enter + ans = 0 + while n != 0: + ans = ans + n + t+=1 + n = float(input("Enter another number (0 to calculate): ")) + return [ans,t] +def subtraction (): + print("Subtraction"); + n = float(input("Enter the number: ")) + t = 0 //Total number enter + sum = 0 + while n != 0: + ans = ans - n + t+=1 + n = float(input("Enter another number (0 to calculate): ")) + return [ans,t] +def multiplication (): + print("Multiplication") + n = float(input("Enter the number: ")) + t = 0 //Total number enter + ans = 1 + while n != 0: + ans = ans * n + t+=1 + n = float(input("Enter another number (0 to calculate): ")) + return [ans,t] +def average(): + an = [] + an = addition() + t = an[1] + a = an[0] + ans = a / t + return [ans,t] +// main... +while True: + list = [] + print(" My first python program!") + print(" Simple Calculator in python by Malik Umer Farooq") + print(" Enter 'a' for addition") + print(" Enter 's' for substraction") + print(" Enter 'm' for multiplication") + print(" Enter 'v' for average") + print(" Enter 'q' for quit") + c = input(" ") + if c != 'q': + if c == 'a': + list = addition() + print("Ans = ", list[0], " total inputs ",list[1]) + elif c == 's': + list = subtraction() + print("Ans = ", list[0], " total inputs ",list[1]) + elif c == 'm': + list = multiplication() + print("Ans = ", list[0], " total inputs ",list[1]) + elif c == 'v': + list = average() + print("Ans = ", list[0], " total inputs ",list[1]) + else: + print ("Sorry, invilid character") + else: + break \ No newline at end of file diff --git a/Program's_Contributed_By_Contributors/Python_Programs/Rock_Paper_Scissors.py b/Program's_Contributed_By_Contributors/Python_Programs/Rock_Paper_Scissors.py new file mode 100644 index 0000000000..44b526e3a6 --- /dev/null +++ b/Program's_Contributed_By_Contributors/Python_Programs/Rock_Paper_Scissors.py @@ -0,0 +1,34 @@ +""" Rock Paper Scissors +---------------------------------------- +""" +import random +import os +import re +os.system('cls' if os.name=='nt' else 'clear') +while (1 < 2): + print "\n" + print "Rock, Paper, Scissors - Shoot!" + userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ") + if not re.match("[SsRrPp]", userChoice): + print "Please choose a letter:" + print "[R]ock, [S]cissors or [P]aper." + continue + // Echo the user's choice + print "You chose: " + userChoice + choices = ['R', 'P', 'S'] + opponenetChoice = random.choice(choices) + print "I chose: " + opponenetChoice + if opponenetChoice == str.upper(userChoice): + print "Tie! " + #if opponenetChoice == str("R") and str.upper(userChoice) == "P" + elif opponenetChoice == 'R' and userChoice.upper() == 'S': + print "Scissors beats rock, I win! " + continue + elif opponenetChoice == 'S' and userChoice.upper() == 'P': + print "Scissors beats paper! I win! " + continue + elif opponenetChoice == 'P' and userChoice.upper() == 'R': + print "Paper beat rock, I win! " + continue + else: + print "You win!" \ No newline at end of file