From 4564ae900d92d2be99a529d4659ae09dca761796 Mon Sep 17 00:00:00 2001 From: Preethi Date: Wed, 17 Oct 2018 22:36:24 -0700 Subject: [PATCH 1/3] roller dice program --- ProblemSolving/gameProgs/rollerdice.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ProblemSolving/gameProgs/rollerdice.py diff --git a/ProblemSolving/gameProgs/rollerdice.py b/ProblemSolving/gameProgs/rollerdice.py new file mode 100644 index 0000000..361c40f --- /dev/null +++ b/ProblemSolving/gameProgs/rollerdice.py @@ -0,0 +1,21 @@ +#Roller dice program + +from random import randint + + + +player1 = randint(1,6) +print ("player1 chance",player1) + + + +player2 = randint(1,6) +print("player2 chance",player2) + +if player1 == player2: + print("draw") +elif player1 > player2: + print("player1 wins") +else: + print("player2 wins") + From 03545d0f6dc72c3d3c77c3c4d2bc8b82ebaafb5d Mon Sep 17 00:00:00 2001 From: Preethi Date: Wed, 17 Oct 2018 23:13:55 -0700 Subject: [PATCH 2/3] Calculator program --- ProblemSolving/gameProgs/rollerdice.py | 5 +- Ruby/ca.rb | 74 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 Ruby/ca.rb diff --git a/ProblemSolving/gameProgs/rollerdice.py b/ProblemSolving/gameProgs/rollerdice.py index 361c40f..f8ee5e7 100644 --- a/ProblemSolving/gameProgs/rollerdice.py +++ b/ProblemSolving/gameProgs/rollerdice.py @@ -3,15 +3,16 @@ from random import randint - +#chooses a random integer from 1 to 6 for player1 player1 = randint(1,6) print ("player1 chance",player1) - +#chooses a random integer from 1 to 6 for player2 player2 = randint(1,6) print("player2 chance",player2) +#Condition to check who wins if player1 == player2: print("draw") elif player1 > player2: diff --git a/Ruby/ca.rb b/Ruby/ca.rb new file mode 100644 index 0000000..ffeb6db --- /dev/null +++ b/Ruby/ca.rb @@ -0,0 +1,74 @@ +#Calculator program +def greeting + + puts "\n" + "I am a simple calculator application" + + +end + +#Operation selection + +puts "\n" + "Type 1 to add, 2 to subtract, 3 to multiply, or 4 to divide two numbers: " + operation_selection = gets.to_i + + if operation_selection == 1 + return "add" + elsif operation_selection == 2 + return "subtract" + elsif operation_selection == 3 + return "multiply" + elsif operation_selection == 4 + return "divide" + else + return "error" + + end + +end + +#Operations performed +def calculate_answer(operator, a, b) + + if operator == "add" + return a + b + elsif operator == "subtract" + return a - b + elsif operator == "multiply" + return a * b + elsif operator == "divide" + return a / b + end + +end + +name = greeting +run_calculator = 1 + +while run_calculator == 1 + + current_calculation = request_calculation_type() + +#Error handling + if current_calculation == "error" + + puts "\n" + "Can we try again?" + + else + puts "\n" + "first number #{current_calculation}: " + first_number = gets.to_i + puts "\n" + "second number #{current_calculation}: " + second_number = gets.to_i + + answer = calculate_answer(current_calculation, first_number, second_number) + + puts "\n" + "The answer is #{answer}" + puts "\n" + "Type 1 to run another calculation or anything else to end: " + run_calculator = gets.to_i + + if run_calculator != 1 + + puts "\n" + "Thanks ;-)" + + end + end +end From 75c799dd16d1fc0c5ef20c9d3e2a9fca1592f553 Mon Sep 17 00:00:00 2001 From: Preethi Date: Thu, 18 Oct 2018 14:25:33 -0700 Subject: [PATCH 3/3] Guess the number --- ProblemSolving/gameProgs/guessnumber.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ProblemSolving/gameProgs/guessnumber.py diff --git a/ProblemSolving/gameProgs/guessnumber.py b/ProblemSolving/gameProgs/guessnumber.py new file mode 100644 index 0000000..0b8663e --- /dev/null +++ b/ProblemSolving/gameProgs/guessnumber.py @@ -0,0 +1,23 @@ +#guess the number +#Import randint from random +from random import randint + +#Choose a random integer from 1 to 10 +choo = randint(1,10) +print choo + +#Declaring the user variable to 0 to start with the loop +user = 0 + +#Check conditions and guess till it arrives at the expected value + +while choo != user: + user = int(raw_input("please enter a value between 1 to 10")) + print user + if choo < user: + print ("please try a lower value") + elif choo > user: + print ("please try a higher value") + +print ("correct guess") +