Python Forum
Need help with code :(
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code :(
#1
I'm new to Python and I have a presentation due in however all my members are not helping or responding the presentation requires us to make uml diagrams such as a use case diagram, activity and class. However the last bit is the python code.

The assignment brief is about sharedpower and how 2 users can register, login and search tool 1 user to hire tools and the other to book tools and collect them or arrange a dispatch driver to drop the tool or deliver it back.

My code is not the best hence why I'm seeking help.

I need help with the interface looping back to search tool and if possible some how make a code to tell python to only allow login if registered because at the minute you can login with anything.

Here are the instructions given to us:

Interface
You may use text based menus similar to the ones you used lab exercises e.g.
1) Login
2) Search for tools
3) Create new account
4) Exit
Enter your choice:
or you may design Graphical User Interface menus if you wish.
Functional logic
You should also write code to implement a version of the basic functions that the system provides, using the techniques you have learned including appropriate data structures and techniques (extending these if you wish)
You are not required to implement a client-server model with network connection.

Here is my code at the moment please don't judge as I'm still trying my best to learn.

#print ("1)Login, 2) search for tools, 3)create new account, 4)exit ")
#Your Choice")

print("_______________________________________________________________________________")

print ("                           Welcome To SharedPower!                            ")

print("_______________________________________________________________________________")

print()

print("                1.Login   2.Register   3.Search Tool   4.Exit                  ")

print("_______________________________________________________________________________")

print()  # for 1 blank line
print()  #for 2 blank line



#Using a while loop in order to get specific input (1,2,3 or 4)  if not then it will keeping looping     
inp = ""
while inp != "1" and inp != "2" and inp!="3" and inp!="4":

#inp will be used to store input from user
    inp = input("                            Select Option (1-4): ")
    print("________________________________________________________________________________")
    
#If input from user is "4" then it will exit
if inp =="4":
    exit()
    
#If input from user is "1" then begin Login
    if inp=="1":
        input1 = input("Enter Username: ")
    print("________________________________________________________________________________")
    input2 = input("Enter Password: ")
    print("________________________________________________________________________________")
    print ("You Are Now Logged In: ")
    print ("Hello,"),print(input1)
    

if inp == "2":

    print("________________________________________________________________________________")


    
    print("Register To SharedPower!")
    print("________________________________________________________________________________")

    
    user = input("Create A Username : ")
    print("________________________________________________________________________________")
    password = input("Create A Password: ")
    print("________________________________________________________________________________")
    
    date_of_birth = input("What Is Your Date Of Birth DD/MM/YY: ")
    print("________________________________________________________________________________")
    print()
    print ("Login:")
    print("________________________________________________________________________________")
    input1 = input("Enter Username: ")
    print("________________________________________________________________________________")
    input2 = input("Enter Password: ")
    print("________________________________________________________________________________")
    print ("You Are Now Logged In: ")
    print ("Hello,"),print(input1)
    
    print("Welcome To SharedPower!")
    print("________________________________________________________________________________")



inp = ""
if inp == "3":
    
    print("                                Search Tools ")

#Here we have created a function in order to tell python to check a users input with the list.

def linearSearch(item,my_list):
    found = False
    position = 0
    while position < len(my_list) and not found:
        if my_list[position] == item:
            found = True
        position = position + 1
    return found

    
#List of tools avalible
Tools = ['sledge hammer','screwdriver','ladder','sander','powerdrill','gluegun','torches','nail gun','planer','battery','power screwdriver']
item = input('Enter The Name Of The Tool:  ')

#If a tool is found within the list it will print tool avaliable
itemFound = linearSearch(item,Tools)
if itemFound:
    print("________________________________________________________________________________")
    print('Tool Is Avaliable For Booking! ')

#If tool not in list of tools it will print not available
else:
    print("________________________________________________________________________________")
    print ('Oops, The Tool Is Not Available Or Doesnt Exist!')
Will appreciate help so badly thanks guy any suggestions please let me know

Full brief

Project Brief
SharedPower is an information system to help tradesmen to share expensive and specialist tools rather than buying them themselves.

• Registered owners add details of the tools they have available including the per day and per half day rate for each unit.

• Other registered users can hire the tools.


• They can search and check the availability of a tool, up to 6 weeks in advance. If a tool is free it can booked for up to 3 days.

• Though tools are usually collected by the hiring user it is possible to arrange a dispatch rider to pick-up or drop off in urgent situations.


• Returning a tool late is fined at double the day rate for every day it is missing.

• Once per month of all users are calculated and accounts are settled.


• A flat charge of £5 is added to all bills for insurance.

• When tools are checked in or out, photos and notes on condition are uploaded to the system.


• If there is a serious issue of damage or cwear with a unit, then insurance company investigates, determines who is at fault and if necessary pays for the repair of the tool.
• When tools are being repaired they are unavailable.
e.g. What are the different roles for the users interacting with the system which functions of the system they use, or interact with, and what information needs to be recorded about each of them? What are the functions the system must provide? How will they be accessed and organised?




Your group must investigate the basic example provided and based on your assumptions outline a clear vision of what the system will do and for whom. Your report should clearly present your groups’ assumptions about the system and description of the services it will provide.
Reply
#2
Start by reposting code in code tags, see BBCODE
Reply
#3
I'd break your programme up into small functions that each do a specific job, such as print the menu, get a valid option from the user, do a login, etc. This will mean the main part of your code is a set of simple calls and a loop.

For example, you could get the option from the user using a function like this:

def getuserinput(allowed):
    while True:
        response = input("\nSelect Option (1-4): ")
        if response in allowed: return response
        print('That is not an available option. Please try again.')
(allowed is a list/set/frozenset of allowable responses, e.g. {'1', '2', '3', '4'}).

You can use a boolean variable to store whether or not someone has logged in. These are often called flags or semaphores. On initialisation of the programme, set your flag to False: loggedin = False, and change it to True on successful login.

In Python, it is common to have a While True: loop as the core of the programme after initialisation. This keeps going until you complete all the required tasks such as until the user selects the exit option:

allowedresponses = frozenset(['1', '2', '3', '4'])   

while True:
    inp = getuserinput(allowedresponses)
    if inp == '4': break
    ...
I am trying to help you, really, even if it doesn't always seem that way
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020