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") + diff --git a/ProblemSolving/gameProgs/rollerdice.py b/ProblemSolving/gameProgs/rollerdice.py new file mode 100644 index 0000000..f8ee5e7 --- /dev/null +++ b/ProblemSolving/gameProgs/rollerdice.py @@ -0,0 +1,22 @@ +#Roller dice program + +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: + print("player1 wins") +else: + print("player2 wins") + 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