Become a premium member to remove ads
Atomicbeast101

Show off your programming skills

6 posts in this topic

Later soon I'll show you all of my wonderful programming projects that I've done in the past 2 years. Please show me your wonderful projects that you have completed. Doesn't matter if it fails or whatever... (Please no illegal ones XD)

 

Thanks!

-Nuke

Share this post


Link to post
Share on other sites

I don't have many, but the ones I do, I'll gladly share at some point (when I'm on my laptop, with net access)

Share this post


Link to post
Share on other sites

Guest Cage The Rage

I think so far www.desirespec.com/beta is looking good.

Coded with bootstrap framework, still a bit to go.

Share this post


Link to post
Share on other sites

I've not started on Java yet, but Python went well...

 

import random


# Imports the random commands library for use later on in the program

playthegame = True

playerwin = 0
compwin = 0
tiegame = 0
# Defines the three global variables for use in the score logging function

playerrock = 0
playerpaper = 0
playerscissors = 0
# Defines the three global variables for use in the computer's intelligent
# tool choices.

def loop ():
print('''***\nWelcome to Python 3 based Rock Paper Scissors!
The aim of the game is to choose either Rock, Paper or Scissors, and defeat
your opponents's choice. The rules to work out who wins are very simple.
Rock blunts Scissors. Scissors cuts paper. Paper covers Rock.

After each round you can choose whether to continue playing, or to exit the
game. You will be asked if you are sure you want to exit the game. A summary
of the game results will be displayed just before the game exits.

Good luck!''')
global playthegame
# playthegame = True
while playthegame == True:
playthegame = game()
finalscores()
finalcheck = input ('''***\nPress ENTER to exit the game. ''')
#
# The loop function is defined here.
# Prints out an introduction to the game, rules for the game and how the
# game is played in this interpretation.
# ~ The text to print is carriage returned over several lines, purely for
# ~ ease of use and reading within the file writing. It also allows for
# ~ an element of word wrapping on the text. Without this, the string of
# ~ text would be several times longer than the width of the computer
# ~ display, making reading and editing more difficult.
#
# Defines the variable 'playthegame' as True (or 1). Whilst True, the function
# 'game' is called. If the value of 'playthegame' become False (i.e. 0) then
# the function will stop calling the 'game' function and instead call the
# 'finalscores' function, and then the 'finalcheck' variable.
#
# The 'finalcheck' variable is not needed here, but is a useful feature to have,
# as it allows the player to look at their scores before exiting the program.
# It also means writing the program in other interpreters, potentially ones
# a GUI, the player will still have control over exiting the program after
# viewing their scores.


def game ():
varP = str(Pinputmenu())
if varP == 'q':
return 0
else:
varC = genC(varP)
result = findwinner(varP, varC)
renewscores(result)
return 1
#
# The 'game' function is defined here.
# The first line on the 'game' function is to set the variable varP as a string of the
# returned input from the 'Pinputmenu' function.
# Then an IF statement is run, to evaluate the string returned from the previous call.
# IF the variable is a lower-case 'Q', then return the value '0'. This causes the value
# of the variable 'playthegame' to become 'False', resulting in the game ending.
#
# ~ I am aware that this isn't an exact implementation of task 3 from the
# ~ coursework handout. However, it is the only way I can ask whether the play wants
# ~ to exit the game. I am happy to show you my previous implementation of this
# ~ function, which explicitly asked whether the player wanted to play again,
# ~ but did not loop back and resume the game correctly.
#
# Otherwise, if the variable has any other value, then the variable 'varC' is set equal
# to the result of the function 'genC', which carries the variable 'varP' as well.
# Then the variable 'result' is set equal to the output of the function 'findwinner',
# which carries both the variables 'varP' and 'varC'.
# After this, the function 'renewscores' is called, which carries the previously defined
# 'result' variable.
# The final step of the 'game' function is to return the value '1' to the previous
# function ('loop') which will set the variable 'playthegame' as True and begin a new
# round of the Rock Paper Scissors game.


def Pinputmenu ():
print('''***\nPlease select a tool to use:
[r]: Rock
[p]: Paper
: Scissors
[q]: Quit game''')
selecttool = input('''Enter your tool choice here: ''')
while not inputvalid(selecttool):
invaltool(selecttool)
selecttool = input('''Please make a valid choice: ''')
return selecttool
#
# The function 'Pinputmenu' is defined here.
# This function will first off print a list of options that the player can enter. These
# represent the choice of tool the player can use to play the game.
# The variable 'selecttool' is then set equal to the input of the player's input.
#
# Once the player inputs a value for the variable the function inputvalid is called,
# carrying the variable selecttool to it can be checked as one of the provided tools.
# If the tool the player selected is not valid, a call is put to the function 'invaltool'
# which prints out the list of options again for the player. The input is then taken
# and validated again through the while loop. This will continue until a valid tool is
# chosen by the player.
#
# Once a valid tool selection is made, the value for the function 'Pinputmenu' is given
# to the function that originally called it (the 'game' function).


def inputvalid(selecttool):
if selecttool == 'r' or selecttool == 'p' or selecttool == 's' or selecttool == 'q':
return True
else:
return False
#
# The function 'inputvalid' is defined here, with the carried variable 'selecttool' from
# the function 'Pinputmenu'.
# This function is very simple, and the only operation is to check whether the variable
# 'selecttool' is either an 'r', a 'p', a 's' or a 'q'. If it is, then tell the function
# that called the inputvalid function (in this case 'Pinputmenu') and tel it the while
# loop is fulfilled, thus needing to stop running and the next line needing to be run.
#
# If the value of selecttool is anything but those four values, the 'inputvalid' function will
# cause the while loop from the 'Pinputmenu' function to run again until a valid input is
# provided by the player.


def genC(varP):
global playerrock, playerpaper, playerscissors

if playerrock > playerpaper and playerrock > playerscissors:
varC = 'p'
return varC
elif playerpaper > playerrock and playerpaper > playerscissors:
varC = 's'
return varC
elif playerscissors > playerrock and playerscissors > playerpaper:
varC = 'r'
return varC
else:
varC = random.choice(['r','p','s'])
return varC
#
# The function 'genC' is defined here.
# The first step in this function is to load the variables 'playerrock', 'playerpaper' and
# 'playerscissors'. These change every time the program completes a cycle, so must reload
# within this function each time as well.
# The function then compares the value of each global variable, to determine the best tool
# for the computer to beat the player with.
# For example, if the player chooses rock a lot, the value of 'playerrock' is larger than
# the other variables. Then this function will see that, and determine, through basic IF
# statement determination, that the tool most likely to beat the player is Paper.
#
# ~ I am aware that this logic is fundamentally flawed. One flaw is that it is extremely
# ~ predictable. If I am playing the game, all I have to do is keep changing the tool I
# ~ use to beat the computer's choice each time.
# ~ A second flaw is that if the global variables are all the same value (i.e. I have used
# ~ Rock, Paper and Scissors 3 times each) all the 'intelligence' statements wil fail, as
# ~ no variable is larger than the other. This will result in the ELSE statement being run.
# ~ Whilst the ELSE statement introduces a random element to the game, it is "completely"
# ~ random, and takes no account of the player's previous tool choices.
#
# ~ If I were to implement this "intelligence" in a different way, it would retain a random
# ~ element regardless of how many times each tool is chosen. However, it is impractical for
# ~ two main reasons. First, it requires writing values to the table of choices for the
# ~ random.choice command. The more games played, the larger the table gets. This uses a lot
# ~ of computer resources and could cause system instability. The second issue is that the
# ~ rest of the program would become more complex, as more calls would be needed to update the
# ~ choices list, even if it were a global entity.


def findwinner(varP, varC):
global playerrock, playerpaper, playerscissors
if varP == 'r':
playerrock +=1
print ('''You chose Rock.''')
if varC == 'r':
print('''The computer chose Rock. \n Tie Game.''')
return 0
elif varC == 'p':
print('''The computer chose Paper. \n Computer Wins.''')
return -1
else:
print('''The computer chose Scissors. \n You Win.''')
return 1
elif varP == 'p':
playerpaper +=1
print ('''You chose Paper.''')
if varC == 'r':
print('''The computer chose Rock. \n You Win.''')
return 1
elif varC == 'p':
print('''The computer chose Paper. \n Tie Game.''')
return 0
else:
print('''The computer chose Scissors. \n Computer Wins.''')
return -1
else:
playerscissors +=1
print('''You chose Scissors.''')
if varC == 'r':
print('''The computer chose Rock. \n Computer Wins.''')
return -1
elif varC == 'p':
print('''The computer chose Paper. \n You Win.''')
return 1
else:
print('''The computer chose Scissors. \n Tie Game.''')
return 0
return playerrock, playerpaper, playerscissors
#
# The function 'findwinner' is defined here. It also carries the
# variables 'varP' and 'varC' from previous functions.
# Then the function will follow a long winded pattern to determine
# the winner of the current round of the game.
#
# First, the function will evaluate which tool the player has chosen.
# For example, if 'varP' is equal to 'r', then the IF statement is
# true, and all lines nested within that IF statement are run.
# Note that if 'varP' is not equal to 'r' or 'p' then it must equal
# 's', as the value has already been validated by the 'inputvalid'
# function. This is why only an IF, an ELIF and an ELSE statement are
# used to work out who wins.
#
# Once the tool of the player has been evaluated (i.e. once either the
# IF, ELIF or ELSE statements that are first run within the function
# have completed) the appropriate variable is updated. For example, if
# the player chooses Paper, the variable 'playerpaper' has 1 added to
# it's existing integer (which starts at 0). This serves as the count
# used by the computer to work out how many times each tool is used.
# Right after this, a message is printed, telling the user exactly which
# tool they have chosen (e.g. You have chosen Paper.).
#
# Then a second set of IF, ELIF and ELSE statements are run. These are the
# statements which determine the victor of each round. For instance, IF
# 'varP' is equal to r, we still need to know what the computer chose to
# see who wins. IF the computer chose scissors ('s') the value of varC is
# 's', which is determined after the IF and ELIF statements from the first
# IF statement of the function. This is only after it has been determined
# that 'varC' does not equal 'r' or 'p', done by the previous IF and ELIF.
#
# Once the outcome is determined, a print commend informs the player of the
# game outcome (e.g. The computer chose paper. You won) and provides an
# integer which is fed back to the 'loop' function, the caller for this
# function. This integer is used later on to calculate the game scores.
#
# Once the outcome of the game is determined, the values of the three global
# variables ('playerrock', 'playerpaper' and 'playerscissors') are fed back
# to their origin via a return command, to ensure they are updated.


def renewscores(result):
global playerwin, compwin, tiegame
if result == 1:
playerwin +=1
elif result == 0:
tiegame +=1
else:
compwin +=1
#
# The function renewscores is defined here.
# This function is called by the 'loop' function after the game outcome ('result')
# has been calculated.
# The global variables 'playerwin', 'compwin' and 'tiegame' are retrieved, with
# an initial value of '0'.
# The 'result' variable is also retrieved, and is used to determine which of the
# global variables needs updating.
# IF, for instance, the value of 'result' is -1, then it is not equal to either
# 1 or 0, so the ELSE statement is true. This causes 1 to be added to the integer
# value of the global variable compwin, which is used to track who many times
# the computer has won a round of the game.


def invaltool(selecttool):
print(selecttool, '''is not a valid selection. Please choose from:
[r]: Rock
[p]: Paper
: Scissors
[q]: Quit game''')
#
# The function 'invaltool' is defined here.
# The role of this funciton is to inform the user they have entered an incorrect
# tool choice, and to remind them of the options.
# ~ I understand that it is unneccessary to have a whole function just to print
# ~ a single message, but by having a function here, I have the option of modifying
# ~ the program, so it can do many other things as well. For instance, if the player
# ~ enters multiple invalid options within a single round, the function could have
# ~ a line added that subtracts a win from their score for wasting time.
# ~ It may sem a bit unfair and unnecessary, but it could be used for rewards too.
# ~ For instance, a count could be run within this function that, after a certain
# ~ number of errors, does something silly, such as print a joke message.
# ~ This would be a sort of easter egg, and encourage people to explore the program's
# ~ code more.


def finalscores():
global playerwin, compwin, tiegame
print('''***\nFinal scores: \n Games you have won:''', playerwin, '''\n Games the computer won:''', compwin, '''\n Tied Games:''', tiegame)
#
# The function 'finalscores' is defined here.
# This function is called af the end of the loop function, and is used to print the
# number of wins, loses and tie games the player has had. the \n in each string is
# used to start a new paragraph. I have done this here as the entire line to print
# fits within the Python editing window, wheras the text printed when the program
# first runs would be much longer.

loop()
# This line at the end is here for two reasons. Firstly, it calls the 'loop' function.
# Secondly, it is at the end of the program so that all the functions and variables
# are acknowledged and loaded properly by the interpreter. If this command was at the
# begginning of the program, none of the functions would be loaded, and so the program
# would fail to run.

 

 

This was one part of an assignment task I had to do. The other part was boring, but here it is as well:

 

'''TASK 1 - Compass Points'''



def turn_clockwise (x): #Begin a function called turn clockwise.
if x == 'N': #Use an IF statement to decide on what to do. If N then change x to E
x = 'E'
elif x == 'E': #Use a second IF statement to decide what to do if x is not N.
x = 'S' #If x was E then change x to S
elif x == 'S': #A third IF statement is used if the first 2 did not succeed.
x = 'W' #If x was S then change x to W
else: #ELSE means if everything else has not worked, do this regardless of any conditions.
x = 'N' #make x N
return(x) #Gives the value of x back to the program

'''TASK 2 - Day Names'''

def day_name(y): #Define a function called day_name

if y == 0 : #IF x is equal to 0, then return the string Sunday to the program
return 'Sunday'

elif y == 1 : #IF x is equal to 1, then return the string Monday to the program
return 'Monday'

elif y == 2 : #IF x is equal to 2, then return the string Tuesday to the program
return 'Tuesday'

elif y == 3 : #IF x is equal to 3, then return the string Wednesday to the program
return 'Wednesday'

elif y == 4 : #IF x is equal to 4, then return the string Thursday to the program
return 'Thursday'

elif y == 5 : #IF x is equal to 5, then return the string Friday to the program
return 'Friday'

elif y == 6 : #IF x is equal to 6, then return the string Saturday to the program
return 'Saturday'

else: #Otherwise, return the string ERROR to the program
return 'None'

'''TASK 3 - Day Numbers'''

def day_num (x): #Define a function called day_num

if x == 'Sunday': #IF x is equal to Sunday, then return the string 0 to the program
return '0'

elif x == 'Monday': #Otherwise IF x is equal to Monday, then return the string 1 to the program
return '1'

elif x == 'Tuesday': #Otherwise IF x is equal to Tuesday, then return the string 2 to the program
return '2'

elif x == 'Wednesday': #Otherwise IF x is equal to Wednesday, then return the string 3 to the program
return '3'

elif x == 'Thursday': #Otherwise IF x is equal to Thursday, then return the string 4 to the program
return '4'

elif x == 'Friday': #OtherwiseIF x is equal to Friday, then return the string 5 to the program
return '5'

elif x == 'Saturday': #Otherwise IF x is equal to Saturday, then return the string 6 to the program
return '6'

else: #ELSE (aka otherwise) return the string None to the program
return ('None')

'''TASK 4 - Holiday Returns Calculator'''

def day_add (hol_leaving, hol_length): # Define a function called day_add

daylist = ['none','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] # Define a list called daylist, with 8 entries

if hol_leaving == 'Monday': # IF the first variable from the test suite is equal to the string Monday, make x equal 1
x = 1
elif hol_leaving == 'Tuesday': # Otherwise, IF the first variable from the test suite is equal to the string Tuesday, make x equal 2
x = 2
elif hol_leaving == 'Wednesday': # Otherwise, IF the first variable from the test suite is equal to the string Wednesday, make x equal 3
x = 3
elif hol_leaving == 'Thursday': # Otherwise, IF the first variable from the test suite is equal to the string Thursday, make x equal 4
x = 4
elif hol_leaving == 'Friday': # Otherwise, IF the first variable from the test suite is equal to the string Friday, make x equal 5
x = 5
elif hol_leaving == 'Saturday': # Otherwise, IF the first variable from the test suite is equal to the string Saturday, make x equal 6
x = 6
elif hol_leaving == 'Sunday': # Otherwise, IF the first variable from the test suite is equal to the string Sunday, make x equal 7
x = 7
else: # Otherwise, make x equal None
x = 'None'

y = hol_length # Set the variable y equal to the value of the variable hol_length from the test_suite

deptime = (x+y) # Set the variable deptime equal to the sum of the value of the variables x and y
hol_dayleave = ((deptime)%7) # set the variable hol_dayleave equal to the remainder of the value for deptime when divided by 7

return (daylist[hol_dayleave]) # return the list entry from the daylist with the positional value equal to the result from the hol_dayleave calculation

'''TASK 5 - Negative Deltas'''

def day_neg (hol_leaving, hol_length): # Define a function called day_neg

daylist = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] # Define a list called daylist, with 7 entries
# This list differs from Task 4's, in that the None entry was removed.

if hol_leaving == 'Monday': # IF the first variable from the test suite is equal to the string Monday, make x equal 1
x = 1
elif hol_leaving == 'Tuesday': # Otherwise, IF the first variable from the test suite is equal to the string Tuesday, make x equal 2
x = 2
elif hol_leaving == 'Wednesday': # Otherwise, IF the first variable from the test suite is equal to the string Wednesday, make x equal 3
x = 3
elif hol_leaving == 'Thursday': # Otherwise, IF the first variable from the test suite is equal to the string Thursday, make x equal 4
x = 4
elif hol_leaving == 'Friday': # Otherwise, IF the first variable from the test suite is equal to the string Friday, make x equal 5
x = 5
elif hol_leaving == 'Saturday': # Otherwise, IF the first variable from the test suite is equal to the string Saturday, make x equal 6
x = 6
else: # hol_leaving == 'Sunday': # Otherwise, IF the first variable from the test suite is equal to the string Sunday, make x equal 7
x = 7

y = hol_length # Set the variable y equal to the value of the variable hol_length from the test_suite

deptime = (x+y)-1 # Set the variable deptime equal to the sum of the value of the variables x and y, then subtract 1 from that value
hol_dayleave = ((deptime)%7) # set the variable hol_dayleave equal to the remainder of the value for deptime when divided by 7

return (daylist[hol_dayleave]) # return the list entry from the daylist with the positional value equal to the result from the hol_dayleave calculation

'''TASK 6 - SECONDS CALCULATOR'''

def to_secs (hours, minutes, seconds): # Define a function called to_secs

secs_from_hrs = int(hours) * 3600 # Set the variable secs_from_hrs equal to the value of the integer set variable hours multiplied by 3600
secs_from_mins = int(minutes) * 60 # Set the variable secs_from_mins equal to the value of the integer set variable minutes multiplied by 60
total_secs = (int(secs_from_hrs))+(int(secs_from_mins))+(int(seconds)) # Set the variable total_secs equal to the value of the sum of the seconds variable from
# testing suite, and the calculated variables secs_from_hrs and secs_from_mins
return (total_secs) # Return the value for the calculation of the total secs

'''TASK 7 - INVERSE to_secs'''

def hours_in (x): # Define a function called hours_in
hin = int(x) // int(3600) # Set the variable hin equal to the variable from the testing suite divided by 3600
x = (int(hin)) # Set the variable x equal to the value of hin
return (x) # Return the variable x to the testing suite

def minutes_in (x): # Define a function called minutes_in
secs_aft_hrs = int(x) % int(3600) # Set the variable secs_aft_hrs equal to the remainder of the value of the variable x from the testing suite divided by 3600
mins_out = int(secs_aft_hrs) // int(60) # Set the variable mins_out equal to the variable secs_aft_hrs divided by 60
x = int(mins_out) # Set the variable x equal to the value of the calculated variable mins_out
return (x) # Return the variable x to the testing suite

def seconds_in (x): # Define a function called seconds_in
secs_rem_aft_h = int(x) % int(3600) # Set the variable secs_rem_aft_h equal to the remainder of the value of the variable x from the testing suite divided by 3600
mins_out = int(secs_rem_aft_h) // int(60) # Set the variable mins_out equal to the variable secs_rem_aft_h divided by 60
secs_out = int(secs_rem_aft_h) % int(60) # Set the variable secs_out equal to the remainder of the variable secs_rem_aft_h divided by 60
x = int(secs_out) # Set the variable x equal to the value of the calculated variable secs_out
return (x) # Return the variable x to the testing suite

'''TASK 8 - Comparing variables'''

def compare (a, B): # Define a function called compare
if a > b: # Use an IF statement to determine whether the variable a is greater than the variable b
return (1) # IF a is greater than b, return the value 1 to the testing suite
elif a==b: # Otherwise, determine IF the variable a is equal to b
return (0) # IF a is equal to b, return the value 0 to the testing suite
else: # Otherwise, IF the previous conditions haven't been met
return (-1) # Return the value -1 to the testing suite


####################
'''TESTING SUITE'''

def test(expected, result): # Define a function called test
import sys # Import the system functions libraries
linenu = sys._getframe(1).f_lineno # set the variable linenu equal to the command sys.getframe(1).f_lineno - a command which returns the line number of a process
if (expected == result): # IF the expected value from the called function is equal to the value given to the testing suite as the expected one, execute the following command(s)
telusr = 'Test on line {0} success.'. format(linenu) # set the variable telusr equal to the string ''Test on line {0} success.'' where {0} represents the line number from the variable linenu
else: # Otherwise, execute the following command
telusr = """Test on line {0} failed. Expected '{1}', but received '{2}'.""". format(linenu, expected, result) # Set the variable telusr the test on the line with value equal to the variable linenu, and tell them what value was received, and what was expected to be returned.
print(telusr) # Print the variable telusr for the user to read


def test_suite(): # Define the function test_suite
print ('\n1. Compass Points') # Print the string ''1. Compass Points'' after externing a carriage return (the \n value).
test(turn_clockwise('N'), 'E') # Call the test function, with the command to call the turn_clockwise function, with the input value as 'N' and the expected value as 'E'
test(turn_clockwise('W'), 'N') # Call the test function, with the command to call the turn_clockwise function, with the input value as 'W' and the expected value as 'N'

print ('\n2. Day Names') # Print the string ''2. Day Names'' after externing a carriage return (the \n value).
test(day_name(3), 'Wednesday') # Call the test function, with the command to call the day_name function, with the input '3' and the expected output as 'Wednesday'.
test(day_name(6), 'Saturday') # Call the test function, with the command to call the day_name function, with the input '6' and the expected output as 'Saturday'.
test(day_name(42), 'None') # Call the test function, with the command to call the day_name function, with the input '42' and the expected output as 'None'.

print ('\n3. Day Numbers') # Print the string ''3. Day Numbers'' after externing a carriage return (the \n value).
test(day_num('Friday'), '5') # Call the test function, with the command to call the day_num function, with the input 'Friday', and the expected output '5'.
test(day_num('Sunday'), '0') # Call the test function, with the command to call the day_num function, with the input 'Sunday', and the expected output '0'
test(day_num(day_name(3)), '3') # Call the test function, with the command to call the day_num function, with the input from the function day_name (using the input of '3'), and the expected output '3'
test(day_name(day_num('Thursday')), 'None') # Call the test function, with the command to call the day_name function, with the input from the function day_num (using the input 'Thursday'), and the expected output 'None'

print ('\n4. Holiday Departure Days') # Print the string ''4. Holiday Departure Days'' after externing a carriage return (the \n value).
test(day_add('Monday', 4), 'Friday') # Call the test function, with the command to call the day_add function, with the inputs 'Monday' and '4', and the expected output of 'Friday'.
test(day_add('Tuesday', 0), 'Tuesday') # Call the test function, with the command to call the day_add function, with the inputs 'Tuesday' and '0', and the expected output of 'Tuesday'.
test(day_add('Tuesday', 14), 'Tuesday') # Call the test function, with the command to call the day_add function, with the inputs 'Tuesday' and '14', and the expected output of 'Tuesday'.
test(day_add('Sunday', 100), 'Tuesday') # Call the test function, with the command to call the day_add function, with the inputs 'Sunday' and '100', and the expected output of 'Tuesday'.

print ('\n5. Day_add Negative Deltas') # Print the string ''5. Day_add Negative Deltas'' after externing a carriage return (the \n value).
test(day_neg('Sunday', -1), 'Saturday') # Call the test function, with the command to call the day_neg function, with the inputs 'Sunday' and '-1', and the expected output of 'Saturday'.
test(day_neg('Sunday', -7), 'Sunday') # Call the test function, with the command to call the day_neg function, with the inputs 'Sunday' and '-7', and the expected output of 'Sunday'.
test(day_neg('Tuesday', -100), 'Sunday') # Call the test function, with the command to call the day_neg function, with the inputs 'Tuesday' and '-100', and the expected output of 'Sunday'.

print ('\n6. Convert to Seconds') # Print the string ''6. Convert to Seconds'' after externing a carriage return (the \n value).
test(to_secs(2, 30, 10),9010) # Call the test function, with the command to call the to_secs function, with the inputs '2', '30', and '10'; and the expected output of 9010.
test(to_secs(2, 0, 0), 7200) # Call the test function, with the command to call the to_secs function, with the inputs '2', '0', and '0'; and the expected output of 7200.
test(to_secs(0, 2, 0), 120) # Call the test function, with the command to call the to_secs function, with the inputs '0', '2', and '0'; and the expected output of 120.
test(to_secs(0, 0, 42), 42) # Call the test function, with the command to call the to_secs function, with the inputs '0', '0', and '42'; and the expected output of 42.
test(to_secs(0, -10, 10), -590) # Call the test function, with the command to call the to_secs function, with the inputs '', '-10', and '10'; and the expected output of -590.

print ('\n7. Convert from seconds') # Print the string ''7. Convert from seconds'' after externing a carriage return (the \n value).
test(hours_in(9010), 2) # Call the test function, with the command to call the hours_in function, with the input '9010' and the expected output of '2'.
test(minutes_in(9010), 30) # Call the test function, with the command to call the minutes_in function, with the input '9010' and the expected output of '30'.
test(seconds_in(9010), 10) # Call the test function, with the command to call the seconds_in function, with the input '9010' and the expceted output of '10'.

print ('\n8. Compare variables') # Print the string ''8. Compare variables'' after externing a carriage return (the \n value).
test(compare(5, 4), 1) # Call the test function, with the command to call the compare function, with the inputs of '5' and '4', and the expected output of '1'.
test(compare(7, 7), 0) # Call the test funciton, with the command to call the compare funciton, with the inputs of '7' and '7', and the expected output of '0'.
test(compare(2, 3), -1) # Call the test funciton, with the command to call the compare funciton, with the inputs of '2' and '3', and the expected output of '-1'.
test(compare(42, 1), 1) # Call the test funciton, with the command to call the compare funciton, with the inputs of '42' and '1', and the expected output of '1'.

test_suite() # Call the test_suite function, with no variables to input. Note that this is the first line of the program that is executed, as it has no indentation, nor is it a definition of a function.

 

DL Links:

 

> RocPapSci Project - https://dl.dropboxusercontent.com/u/39026697/RND/%7ECode/RocPapScis%20V3.0.4.py

> Testing Suite - https://dl.dropboxusercontent.com/u/39026697/RND/%7ECode/Assn1%20v1.4.4-00104.py

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now