Jump to content

Python

Haeking

image.png.a9b2d06347835e1ff65446de43eec520.pngimage.png.ff66ad794d0338aef161b69857e48a1e.png

I was wondering if someone could explain this python coding to me in detail, Im having a hard time understanding it 
What would be the simplest way, to get to the final solution, and why ?
So I can understand the thinking pattern of someone 

Link to comment
Share on other sites

Link to post
Share on other sites

They want you to use variables, input(), while True loop, do string formatting with a print statement, do math operations, etc etc etc...

 

Here is a documented sample that does most of these things.  Pseudo code is mostly non-existant, but comments are generous.  The code does not handle improper input, but it does not seem your examples require this.  It will not be the exact program you are being asked for.

 

 

"""
Program = Total income calculator
Author = 
Purpose = Calculate income based wage and hours worked


Structure...

    Gather user input for wage, normal hours, and OT hours
    Calculate normal pay, OT pay, and total pay
    Display normal pay, OT pay, and total pay
"""

#define static variable for OT rate
statOTRate = 1.5



#take input for hourly wage as float, store in hourlyWage
hourlyWage = float(input("What is your hourly wage?"))
#take input for normal time hours as float, store in standardHours
standardHours = float(input("How many normal hours did you work?"))
#take input for overtime hours as float, store in overtimeHours
overtimeHours = float(input("How many overtime hours did you work?"))



#calculate normal time pay, store in normalPay
normalPay = hourlyWage * standardHours
#calculate overtime pay, store in overtimePay
overtimePay = hourlyWage * overtimeHours * statOTRate
#calculate total pay, store in totalPay
totalPay = normalPay + overtimePay



#display results of calculations in an easy to understand format, rounded to the nearest cent
print ("Your normal time pay is...")
print ("${:.2f}\n".format(round(normalPay,2)))
print ("Your overtime pay is...")
print ("${:.2f}\n".format(round(overtimePay,2)))
print ("Your total pay is...")
print ("${:.2f}".format(round(totalPay,2)))

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, KarathKasun said:

They want you to use variables, input(), while True loop, do string formatting with a print statement, do math operations, etc etc etc...

 

Here is a documented sample that does these things.  Pseudo code is mostly non-existant, but comments are generous.  The code does not handle improper input, but it does not seem your examples require this.  It will not be the exact program you are being asked for.

 

 


"""
Program = Total income calculator
Author = 
Purpose = Calculate income based wage and hours worked


Structure...

    Gather user input for wage, normal hours, and OT hours
    Calculate normal pay, OT pay, and total pay
    Display normal pay, OT pay, and total pay
"""

#define static variable for OT rate
statOTRate = 1.5



#take input for hourly wage as float, store in hourlyWage
hourlyWage = float(input("What is your hourly wage?"))
#take input for normal time hours as float, store in standardHours
standardHours = float(input("How many normal hours did you work?"))
#take input for overtime hours as float, store in overtimeHours
overtimeHours = float(input("How many overtime hours did you work?"))



#calculate normal time pay, store in normalPay
normalPay = hourlyWage * standardHours
#calculate overtime pay, store in overtimePay
overtimePay = hourlyWage * overtimeHours * statOTRate
#calculate total pay, store in totalPay
totalPay = normalPay + overtimePay



#display results of calculations in an easy to understand format, rounded to the nearest cent
print ("Your normal time pay is...")
print ("${:.2f}".format(round(normalPay,2)))
print ("\n")
print ("Your overtime pay is...")
print ("${:.2f}".format(round(overtimePay,2)))
print ("\n")
print ("Your total pay is...")
print ("${:.2f}".format(round(totalPay,2)))

 

Ahh okay, Im getting more of an understanding since of the pseudo code you sent me
Its a lot more split up and to the point then the way he was describing in class
Still is a little bit blurry in some areas 

Link to comment
Share on other sites

Link to post
Share on other sites

Here is a more complete example with better pseudocode.  Hadnt gotten into functions at the time, so menus are a bit... long winded.  Comments only cover sections of the code where things are not largely the same.

 

'''

Convert numbers into binary, octal, or hexidecimal and back while logging output.
**may contain easter eggs, be the first to get ye flask!**
Thy Dungeonman! references belong to homestarrunner.com


Variables...
getUserInput1
getUserInput2
getInputNumber
outputNumber
userOutFile
outFile

-----------------------------------------------------

DISPLAY "Enter a name for the log file"

Get user input and store in userOutFile


REPEAT UNTIL BREAK

    DISPLAY
    "
    Enter 2 to convert from binary
    Enter 8 to convert from octal
    Enter 10 to convert from decimal
    Enter 16 to convert from hexidecimal
    Enter Q to quit
    "

    Get user input and store in getUserInput1

    IF getUserInput = 2

        REPEAT UNTIL BREAK

            DISPLAY "Enter your binary number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Oct outputNumber"
                DISPLAY "Bin getInputNumber = Oct outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Dec outputNumber"
                DISPLAY "Bin getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Hex outputNumber"
                DISPLAY "Bin getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 8

        REPEAT UNTIL BREAK

            DISPLAY "Enter your octal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Bin outputNumber"
                DISPLAY "Oct getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Dec outputNumber"
                DISPLAY "Oct getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Hex outputNumber"
                DISPLAY "Oct getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 10

        REPEAT UNTIL BREAK

            DISPLAY "Enter your Decimal number"

            Get user input and store in getInputNumber

            DISPLAY
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Bin outputNumber"
                DISPLAY "Dec getInputNumber = Bin outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Oct outputNumber"
                DISPLAY "Dec getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Hex outputNumber"
                DISPLAY "Dec getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 16

        REPEAT UNTIL BREAK

            DISPLAY "Enter your hexidecimal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Bin outputNumber"
                DISPLAY "Hex getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Oct outputNumber"
                DISPLAY "Hex getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Dec outputNumber"
                DISPLAY "Hex getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                Display the following message
                "Invalid input, try again"

    IF getUserInput = Q or q

        DISPLAY "Exiting program..."

        BREAK


'''

#1 import os for disk function, initialize variables, get input for userOutFile variable
import os
getYeFlask=0
strYeFlask="\nYe cannot get the FLASK.  It is firmly\nbolted to a wall which is bolted to the\nrest of the dungeon which is probably\nbolted to a castle.  Never you mind."
strYeFlask2="\nOkay, okay.  You unbolt yon FLASK and hold\nit aloft.  A great shaking begins.  The\ndungeon ceiling collapses down upon you,\ncrushing you in twain.  Apparently, this was\na load-bearing FLASK.\nYour score was: -998\nGAME OVER"
userOutFile = str(input("Enter a name for the log file: "))


#2 main loop
while True:

    #3 display main menu, get use menu selection, if statements for handling main menu user input
    print("\nEnter 2 to convert from binary\nEnter 8 to convert from octal\nEnter 10 to convert from decimal\nEnter 16 to convert from hexidecimal\nEnter Q to quit\n")
    getUserInput1 = str(input(":"))

        
    if getUserInput1 == str("2"):
        
        #4 get input for conversion from binary
        print("\nEnter your binary number\n")
        getInputNumber = str(input(":"))

        #5 loop for "convert from binary menu"
        while True:

            #6 display menu, get input for menu, if statements to handle input
            print("\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("8"):
                
                #7 convert getInputNumber to an integer, convert that to octal,
                #remove 0o from oct() function output, create outString, open the log file
                #concatenate outString with a newline character, write that to outFile/log
                #display outString concatenated with newline and "Convert to another base?" message
                #close outFile
                outNumber = str(oct(int(getInputNumber,2))).replace("0o","")
                outString = "Binary " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):
                
                #see number 7, small changes
                outNumber = str(int(getInputNumber,2))
                outString = "Binary " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                #see #7, small changes
                outNumber = str(hex(int(getInputNumber,2))).replace("0x","")
                outString = "Binary " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):
                
                #8 break menu loop for sub menu
                print("Returning to main menu...")

                break

            else:
                
                #9 handle invalid menu selection
                print("Invalid input!")


#Code beyond this point is largely the same as above with small changes to change to different bases
#End of the program does contain an easter egg, #10

    elif getUserInput1 == str(8):



        print("\nEnter your octal number\n")
        getInputNumber = str(input(":"))

        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,8))).replace("0b","")
                outString = "Octal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,8))
                outString = "Octal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(int(getInputNumber,8))).replace("0x","")
                outString = "Octal " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")

                

    elif getUserInput1 == str(10):



        print("\nEnter your decimal number\n")
        getInputNumber = int(input(":"))
        
        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(getInputNumber)).replace("0b","")
                outString = "Decimal " + str(getInputNumber) + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(getInputNumber)).replace("0o","")
                outString = "Decimal " + str(getInputNumber) + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(getInputNumber)).replace("0x","")
                outString = "Decimal " + str(getInputNumber) + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
            
                                 

    elif getUserInput1 == str(16):



        print("\nEnter your hexidecimal number\n")
        getInputNumber = str(input(":"))
        
        while True:
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,16))).replace("0b","")
                outString = "Hexidecimal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(int(getInputNumber,16))).replace("0o","")
                outString = "Hexidecimal " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,16))
                outString = "Hexidecimal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
                                 
            

    elif getUserInput1.lower() == str("q"):
                                 
        print("\nExiting program...")
                                 
        break

    #10 BONUS/EASTER EGG
    elif getUserInput1.lower() == str("get ye flask"):

        if getYeFlask == 2:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask2 + "\n")
            outFile.close()
            print(strYeFlask2)
            break

        else:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask + "\n")
            outFile.close()
            print(strYeFlask)
            getYeFlask += 1
        

    else:
        print("INVALID INPUT MORTAL!")

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, KarathKasun said:

Here is a more complete example with better pseudocode.  Hadnt gotten into functions at the time, so menus are a bit... long winded.  Comments only cover sections of the code where things are not largely the same.

 


'''

Convert numbers into binary, octal, or hexidecimal and back while logging output.
**may contain easter eggs, be the first to get ye flask!**
Thy Dungeonman! references belong to homestarrunner.com


Variables...
getUserInput1
getUserInput2
getInputNumber
outputNumber
userOutFile
outFile

-----------------------------------------------------

DISPLAY "Enter a name for the log file"

Get user input and store in userOutFile


REPEAT UNTIL BREAK

    DISPLAY
    "
    Enter 2 to convert from binary
    Enter 8 to convert from octal
    Enter 10 to convert from decimal
    Enter 16 to convert from hexidecimal
    Enter Q to quit
    "

    Get user input and store in getUserInput1

    IF getUserInput = 2

        REPEAT UNTIL BREAK

            DISPLAY "Enter your binary number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Oct outputNumber"
                DISPLAY "Bin getInputNumber = Oct outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Dec outputNumber"
                DISPLAY "Bin getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Hex outputNumber"
                DISPLAY "Bin getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 8

        REPEAT UNTIL BREAK

            DISPLAY "Enter your octal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Bin outputNumber"
                DISPLAY "Oct getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Dec outputNumber"
                DISPLAY "Oct getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Hex outputNumber"
                DISPLAY "Oct getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 10

        REPEAT UNTIL BREAK

            DISPLAY "Enter your Decimal number"

            Get user input and store in getInputNumber

            DISPLAY
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Bin outputNumber"
                DISPLAY "Dec getInputNumber = Bin outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Oct outputNumber"
                DISPLAY "Dec getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Hex outputNumber"
                DISPLAY "Dec getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 16

        REPEAT UNTIL BREAK

            DISPLAY "Enter your hexidecimal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Bin outputNumber"
                DISPLAY "Hex getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Oct outputNumber"
                DISPLAY "Hex getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Dec outputNumber"
                DISPLAY "Hex getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                Display the following message
                "Invalid input, try again"

    IF getUserInput = Q or q

        DISPLAY "Exiting program..."

        BREAK


'''

#1 import os for disk function, initialize variables, get input for userOutFile variable
import os
getYeFlask=0
strYeFlask="\nYe cannot get the FLASK.  It is firmly\nbolted to a wall which is bolted to the\nrest of the dungeon which is probably\nbolted to a castle.  Never you mind."
strYeFlask2="\nOkay, okay.  You unbolt yon FLASK and hold\nit aloft.  A great shaking begins.  The\ndungeon ceiling collapses down upon you,\ncrushing you in twain.  Apparently, this was\na load-bearing FLASK.\nYour score was: -998\nGAME OVER"
userOutFile = str(input("Enter a name for the log file: "))


#2 main loop
while True:

    #3 display main menu, get use menu selection, if statements for handling main menu user input
    print("\nEnter 2 to convert from binary\nEnter 8 to convert from octal\nEnter 10 to convert from decimal\nEnter 16 to convert from hexidecimal\nEnter Q to quit\n")
    getUserInput1 = str(input(":"))

        
    if getUserInput1 == str("2"):
        
        #4 get input for conversion from binary
        print("\nEnter your binary number\n")
        getInputNumber = str(input(":"))

        #5 loop for "convert from binary menu"
        while True:

            #6 display menu, get input for menu, if statements to handle input
            print("\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("8"):
                
                #7 convert getInputNumber to an integer, convert that to octal,
                #remove 0o from oct() function output, create outString, open the log file
                #concatenate outString with a newline character, write that to outFile/log
                #display outString concatenated with newline and "Convert to another base?" message
                #close outFile
                outNumber = str(oct(int(getInputNumber,2))).replace("0o","")
                outString = "Binary " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):
                
                #see number 7, small changes
                outNumber = str(int(getInputNumber,2))
                outString = "Binary " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                #see #7, small changes
                outNumber = str(hex(int(getInputNumber,2))).replace("0x","")
                outString = "Binary " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):
                
                #8 break menu loop for sub menu
                print("Returning to main menu...")

                break

            else:
                
                #9 handle invalid menu selection
                print("Invalid input!")


#Code beyond this point is largely the same as above with small changes to change to different bases
#End of the program does contain an easter egg, #10

    elif getUserInput1 == str(8):



        print("\nEnter your octal number\n")
        getInputNumber = str(input(":"))

        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,8))).replace("0b","")
                outString = "Octal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,8))
                outString = "Octal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(int(getInputNumber,8))).replace("0x","")
                outString = "Octal " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")

                

    elif getUserInput1 == str(10):



        print("\nEnter your decimal number\n")
        getInputNumber = int(input(":"))
        
        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(getInputNumber)).replace("0b","")
                outString = "Decimal " + str(getInputNumber) + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(getInputNumber)).replace("0o","")
                outString = "Decimal " + str(getInputNumber) + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(getInputNumber)).replace("0x","")
                outString = "Decimal " + str(getInputNumber) + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
            
                                 

    elif getUserInput1 == str(16):



        print("\nEnter your hexidecimal number\n")
        getInputNumber = str(input(":"))
        
        while True:
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,16))).replace("0b","")
                outString = "Hexidecimal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(int(getInputNumber,16))).replace("0o","")
                outString = "Hexidecimal " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,16))
                outString = "Hexidecimal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
                                 
            

    elif getUserInput1.lower() == str("q"):
                                 
        print("\nExiting program...")
                                 
        break

    #10 BONUS/EASTER EGG
    elif getUserInput1.lower() == str("get ye flask"):

        if getYeFlask == 2:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask2 + "\n")
            outFile.close()
            print(strYeFlask2)
            break

        else:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask + "\n")
            outFile.close()
            print(strYeFlask)
            getYeFlask += 1
        

    else:
        print("INVALID INPUT MORTAL!")

 

Thank you so much
This is helping me a lot more than before 

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, KarathKasun said:

They want you to use variables, input(), while True loop, do string formatting with a print statement, do math operations, etc etc etc...

 

Here is a documented sample that does most of these things.  Pseudo code is mostly non-existant, but comments are generous.  The code does not handle improper input, but it does not seem your examples require this.  It will not be the exact program you are being asked for.

 

 


"""
Program = Total income calculator
Author = 
Purpose = Calculate income based wage and hours worked


Structure...

    Gather user input for wage, normal hours, and OT hours
    Calculate normal pay, OT pay, and total pay
    Display normal pay, OT pay, and total pay
"""

#define static variable for OT rate
statOTRate = 1.5



#take input for hourly wage as float, store in hourlyWage
hourlyWage = float(input("What is your hourly wage?"))
#take input for normal time hours as float, store in standardHours
standardHours = float(input("How many normal hours did you work?"))
#take input for overtime hours as float, store in overtimeHours
overtimeHours = float(input("How many overtime hours did you work?"))



#calculate normal time pay, store in normalPay
normalPay = hourlyWage * standardHours
#calculate overtime pay, store in overtimePay
overtimePay = hourlyWage * overtimeHours * statOTRate
#calculate total pay, store in totalPay
totalPay = normalPay + overtimePay



#display results of calculations in an easy to understand format, rounded to the nearest cent
print ("Your normal time pay is...")
print ("${:.2f}\n".format(round(normalPay,2)))
print ("Your overtime pay is...")
print ("${:.2f}\n".format(round(overtimePay,2)))
print ("Your total pay is...")
print ("${:.2f}".format(round(totalPay,2)))

 

Im stuggling myself I just got into coding (with python and others) Are you able to give me a example of the veriables in action with a if statement to create a outcome with a specific ammount. 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Difice said:

Im stuggling myself I just got into coding (with python and others) Are you able to give me a example of the veriables in action with a if statement to create a outcome with a specific ammount. 

Check my 2nd post.  Code in that program handles variables and text menus with if/elif/else statements.

 

The code at the top is industry standardish pseudocode.  Real python starts at about halfway down after the comment ending ''' and the #1 comment.

Link to comment
Share on other sites

Link to post
Share on other sites

If you want the 2nd example, the base converter, to make more sense with the pseudocode... Copy paste the pseudo code into notepad and line it up with the start of the python code, side by side.  Then you can see what python code relates to what the pseudo code is saying to do.

 

The first "REPEAT UNTIL BREAK" corresponds to the first "while True:"

Link to comment
Share on other sites

Link to post
Share on other sites

On 10/24/2018 at 5:17 AM, KarathKasun said:

Here is a more complete example with better pseudocode.  Hadnt gotten into functions at the time, so menus are a bit... long winded.  Comments only cover sections of the code where things are not largely the same.

 


'''

Convert numbers into binary, octal, or hexidecimal and back while logging output.
**may contain easter eggs, be the first to get ye flask!**
Thy Dungeonman! references belong to homestarrunner.com


Variables...
getUserInput1
getUserInput2
getInputNumber
outputNumber
userOutFile
outFile

-----------------------------------------------------

DISPLAY "Enter a name for the log file"

Get user input and store in userOutFile


REPEAT UNTIL BREAK

    DISPLAY
    "
    Enter 2 to convert from binary
    Enter 8 to convert from octal
    Enter 10 to convert from decimal
    Enter 16 to convert from hexidecimal
    Enter Q to quit
    "

    Get user input and store in getUserInput1

    IF getUserInput = 2

        REPEAT UNTIL BREAK

            DISPLAY "Enter your binary number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Oct outputNumber"
                DISPLAY "Bin getInputNumber = Oct outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Dec outputNumber"
                DISPLAY "Bin getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Bin getInputNumber = Hex outputNumber"
                DISPLAY "Bin getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 8

        REPEAT UNTIL BREAK

            DISPLAY "Enter your octal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 10 to convert to decimal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Bin outputNumber"
                DISPLAY "Oct getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Dec outputNumber"
                DISPLAY "Oct getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Oct getInputNumber = Hex outputNumber"
                DISPLAY "Oct getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 10

        REPEAT UNTIL BREAK

            DISPLAY "Enter your Decimal number"

            Get user input and store in getInputNumber

            DISPLAY
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 16 to convert to hexidecimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Bin outputNumber"
                DISPLAY "Dec getInputNumber = Bin outputNumber"
                CLOSE outFile

                

            ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Oct outputNumber"
                DISPLAY "Dec getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 16

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Dec getInputNumber = Hex outputNumber"
                DISPLAY "Dec getInputNumber = Hex outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                DISPLAY "Invalid input, try again"

    IF getUserInput = 16

        REPEAT UNTIL BREAK

            DISPLAY "Enter your hexidecimal number"

            Get user input and store in getInputNumber

            Display the following menu
            "
            Enter 2 to convert to binary
            Enter 8 to convert to octal
            Enter 10 to convert to decimal
            Enter Q to return to main menu
            "

            Get user input and store in getUserInput2
    
            IF getUserInput2 = 2

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Bin outputNumber"
                DISPLAY "Hex getInputNumber = Bin outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 8

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Oct outputNumber"
                DISPLAY "Hex getInputNumber = Oct outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = 10

                OPEN userOutFile as outFile for appending
                Convert getInputNumber to octal, storing to outputNumber variable
                Write to outFile "Hex getInputNumber = Dec outputNumber"
                DISPLAY "Hex getInputNumber = Dec outputNumber"
                CLOSE outFile

                

             ELSE IF getUserInput2 = Q or q

                DISPLAY "Returning to main menu..."

                BREAK

             ELSE

                Display the following message
                "Invalid input, try again"

    IF getUserInput = Q or q

        DISPLAY "Exiting program..."

        BREAK


'''

#1 import os for disk function, initialize variables, get input for userOutFile variable
import os
getYeFlask=0
strYeFlask="\nYe cannot get the FLASK.  It is firmly\nbolted to a wall which is bolted to the\nrest of the dungeon which is probably\nbolted to a castle.  Never you mind."
strYeFlask2="\nOkay, okay.  You unbolt yon FLASK and hold\nit aloft.  A great shaking begins.  The\ndungeon ceiling collapses down upon you,\ncrushing you in twain.  Apparently, this was\na load-bearing FLASK.\nYour score was: -998\nGAME OVER"
userOutFile = str(input("Enter a name for the log file: "))


#2 main loop
while True:

    #3 display main menu, get use menu selection, if statements for handling main menu user input
    print("\nEnter 2 to convert from binary\nEnter 8 to convert from octal\nEnter 10 to convert from decimal\nEnter 16 to convert from hexidecimal\nEnter Q to quit\n")
    getUserInput1 = str(input(":"))

        
    if getUserInput1 == str("2"):
        
        #4 get input for conversion from binary
        print("\nEnter your binary number\n")
        getInputNumber = str(input(":"))

        #5 loop for "convert from binary menu"
        while True:

            #6 display menu, get input for menu, if statements to handle input
            print("\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("8"):
                
                #7 convert getInputNumber to an integer, convert that to octal,
                #remove 0o from oct() function output, create outString, open the log file
                #concatenate outString with a newline character, write that to outFile/log
                #display outString concatenated with newline and "Convert to another base?" message
                #close outFile
                outNumber = str(oct(int(getInputNumber,2))).replace("0o","")
                outString = "Binary " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):
                
                #see number 7, small changes
                outNumber = str(int(getInputNumber,2))
                outString = "Binary " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                #see #7, small changes
                outNumber = str(hex(int(getInputNumber,2))).replace("0x","")
                outString = "Binary " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):
                
                #8 break menu loop for sub menu
                print("Returning to main menu...")

                break

            else:
                
                #9 handle invalid menu selection
                print("Invalid input!")


#Code beyond this point is largely the same as above with small changes to change to different bases
#End of the program does contain an easter egg, #10

    elif getUserInput1 == str(8):



        print("\nEnter your octal number\n")
        getInputNumber = str(input(":"))

        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 10 to convert to decimal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,8))).replace("0b","")
                outString = "Octal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,8))
                outString = "Octal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(int(getInputNumber,8))).replace("0x","")
                outString = "Octal " + getInputNumber + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")

                

    elif getUserInput1 == str(10):



        print("\nEnter your decimal number\n")
        getInputNumber = int(input(":"))
        
        while True:
            
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 16 to convert to hexidecimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(getInputNumber)).replace("0b","")
                outString = "Decimal " + str(getInputNumber) + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(getInputNumber)).replace("0o","")
                outString = "Decimal " + str(getInputNumber) + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("16"):

                outNumber = str(hex(getInputNumber)).replace("0x","")
                outString = "Decimal " + str(getInputNumber) + " = Hexidecimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
            
                                 

    elif getUserInput1 == str(16):



        print("\nEnter your hexidecimal number\n")
        getInputNumber = str(input(":"))
        
        while True:
            print("\nEnter 2 to convert to binary\nEnter 8 to convert to octal\nEnter 10 to convert to decimal\nEnter Q to return to main menu\n")
            getUserInput2 = str(input(":"))

            if getUserInput2.lower() == str("2"):

                outNumber = str(bin(int(getInputNumber,16))).replace("0b","")
                outString = "Hexidecimal " + getInputNumber + " = Binary " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("8"):

                outNumber = str(oct(int(getInputNumber,16))).replace("0o","")
                outString = "Hexidecimal " + getInputNumber + " = Octal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()

            elif getUserInput2.lower() == str("10"):

                outNumber = str(int(getInputNumber,16))
                outString = "Hexidecimal " + getInputNumber + " = Decimal " + outNumber
                outFile = open(userOutFile+".txt","a")
                outFile.write(outString + "\n")
                print("\n" + outString + "\n\nConvert to another base?")
                outFile.close()
                                 
            elif getUserInput2.lower() == str("q"):

                print("Returning to main menu...")

                break

            else:

                print("Invalid input!")
                                 
            

    elif getUserInput1.lower() == str("q"):
                                 
        print("\nExiting program...")
                                 
        break

    #10 BONUS/EASTER EGG
    elif getUserInput1.lower() == str("get ye flask"):

        if getYeFlask == 2:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask2 + "\n")
            outFile.close()
            print(strYeFlask2)
            break

        else:
            outFile = open(userOutFile+".txt","a")
            outFile.write(strYeFlask + "\n")
            outFile.close()
            print(strYeFlask)
            getYeFlask += 1
        

    else:
        print("INVALID INPUT MORTAL!")

 

See how in the conversion to binary your basically repeating your self over and over?

 

They are a perfect example of when you should refactor that into a single function that you pass data too.

 

If you find yourself repeating code you're doing something wrong.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, vorticalbox said:

See how in the conversion to binary your basically repeating your self over and over?

 

They are a perfect example of when you should refactor that into a single function that you pass data too.

 

If you find yourself repeating code you're doing something wrong.

I am aware of this, but the class had not moved into functions at the time so I used what was covered up to that point to make the program.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, KarathKasun said:

I am aware of this, but the class had not moved into functions at the time so I used what was covered up to that point to make the program.

That's a slow moving class :/ If I were a teacher after learning basic operations I would move on to functions.

 

No point letting people code wrong to then have to relearn the thought process.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, vorticalbox said:

That's a slow moving class :/ If I were a teacher after learning basic operations I would move on to functions.

 

No point letting people code wrong to then have to relearn the thought process.

It was for something like the third class meeting.

Link to comment
Share on other sites

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

×