Sie sind auf Seite 1von 2

#Name:M.

Waleed Liaqat
#Student Number:10385830
#Unit Name :Programming Principle CSP5110
#Instructor name:Greg BAATARD
#Campus:Joondalup

function inputInt(prompt):
Endless loop:
Exception handling if the user enter other then
If user input int is < 1:
print ""It should be at least 1 or greater""
Else:
Break;
if user donot enter integer or less then 1 show this message
"Enter Integer greater then 1 or integer value"
Return int
function inputSomething(prompt):
Endless loop:
store the user input in variable
If user input is empty
Print "Please Enter SomeThing!"
Else:
Break
Return userinput
function saveChanges(datalist):
Open data.txt file in write mode
write the data to file as json
close the json file
print("Data of Game updated successfully!")
function main():
open data file in read mode
Load the json file and store the data to datalist
close the json file
initialize the empty data list
print('Welcome to Game Finder Admin !!')
Endless loop:
Print "Choose [a]dd, [l]ist , s[earch], [v]iew, [d]elete or [q]u
it."
If userinput equal to a
callling input_something function'Enter the name of the
new game' and store it as nameOfGame
calling input_int function'Enter the min players' and st
ore it as minPlayer
calling input_int funtion'Enter the max players' and sto
re it as maxPlayers
calling input_int function'Enter the duration of game' a
nd store it as duration
calling input_int function'Min recommended player age: '
and store it as age
Append nameOfGame, minPlayers, maxPlayers, duration and

age in dict
Append dictionary to our data list
Pass our data list to function save_changes()
Else if UserInput equal to l
If data is not empty
Loop through enumerated data giving index
Print " index and name of the game"
Else if UserInput is equal to s
Calling inputSomething function What would you wish to s
earch and store it as game
Lowercase the game letter
Initiate no_match count to 0
Loop through each item of data
If game name in lowercase matches item name in l
owercase:
Print item and its name
Else
Increment no_match variable by 1
If userinput is equal to Length of data index:
print'"'+game+'" This Game is Not in the list , you have
to add it!'
Else if userinput equalto v
If data is not empty:
Call inputInt Enter the index of game and store
it as index-1
game = dataindex
print"Name of the Game: ", game['name'])
print"Min Players: ", game['min'])
print"Max Player: ", game['max'])
print"Duration of Game: ", game['duration'])
print"Min Age: ", game['age'])
Else: Print "No Games Saved"
Else if userinput is equal to d
If data is not empty:
index = inputInt Enter index of the game you want to delete!
delete the data which is selected by the
user
Else

Call function save_changes data


Print "The game is successfully deleted"
Print "No Games Saved"

Else if userinput is equal too q


Print "Program is Quit
Break from endless loop
Call function main()

Das könnte Ihnen auch gefallen