Skip to content

Game programs2 #9

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 3 commits into
base: master
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
23 changes: 23 additions & 0 deletions ProblemSolving/gameProgs/guessnumber.py
Original file line number Diff line number Diff line change
@@ -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")

22 changes: 22 additions & 0 deletions ProblemSolving/gameProgs/rollerdice.py
Original file line number Diff line number Diff line change
@@ -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")

74 changes: 74 additions & 0 deletions Ruby/ca.rb
Original file line number Diff line number Diff line change
@@ -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