Python Forum
Project cus im borred
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project cus im borred
#1
Any ideas how to get this thing better?
While looking at this, have on your mind that its not finished and that im 14 yrs old.
Also, i have OCD, thats why everything is so... OCDish...

EDIT: Now when i think about it, i have rly only 2 questions, do i really need to type inport time every
time i want to use it and how can i make this program loop, so like, when it gets to end of calculating, that
there is option based on user input to end/exit app or to restart it back to start and so it again asks...
print('')
print('')
print('Calculator v3.1 by M4J0R1C47')
print('')
print('')
print('NOTE: Decimals (as variables, if there is decimals in result that will')
print('still work...)are not quite working in some tasks...yet...')
print('')
print('')
print('SELECT DESIRED TASK GROUP:')
print('')
print('')


#choices

print('1 = Basic tasks (+, -, multiplying, dividing)')
print('2 = Advanced tasks (root, square)')
print('3 = Multiplying tasks (simple multiplying tasks)')
print('4 = Dividing tasks (simple dividing tasks)')
print('__________')
print('')

taskgroup = input()
print('__________')
print('')

...and so on...
...i tried just duplicating code under itself several times so it looks like its looping but rly its pointless
and i cant make it loop forever that way... i looked up how to do it but i dont really understand it...

#start

print('')
print('')
print('Calculator v3.1 by M4J0R1C47')
print('')
print('')
print('NOTE: Decimals (as variables, if there is decimals in result that will')
print('still work...)are not quite working in some tasks...yet...')
print('')
print('')
print('SELECT DESIRED TASK GROUP:')
print('')
print('')


#choices

print('1 = Basic tasks (+, -, multiplying, dividing)')
print('2 = Advanced tasks (root, square)')
print('3 = Multiplying tasks (simple multiplying tasks)')
print('4 = Dividing tasks (simple dividing tasks)')
print('__________')
print('')

taskgroup = input()
print('__________')
print('')

if int(taskgroup) == 1:
    print('Basic tasks:')
    print('1 = X+Y=?')
    print('2 = X-Y=?')
    print('3 = X*Y=?')
    print('4 = X/Y=?')
    print('__________')
    print('')

if int(taskgroup) == 2:
    print('Advanced tasks:')
    print('5 = X square')
    print('6 = X square * Y square')
    print('7 = X square / Y square')
    print('8 = X root')
    print('__________')
    print('')

if int(taskgroup) == 3:
    print('Multiplying tasks:')
    print('9 = X+(Y*Z)=?')
    print('10 = X*(Y+Z)=?')
    print('11 = X-(Y*Z)=?')
    print('12 = X*(Y-Z)=?')
    print('__________')
    print('')

if int(taskgroup) == 4:
    print('Dividing tasks:')
    print('13 = X+(Y/Z)=?')
    print('14 = X/(Y+Z)=?')
    print('15 = (Y+Z)/X=?')
    print('16 = X-(Y/Z)=?')
    print('17 = X/(Y-Z)=?')
    print('18 = (Y-Z)/X=?')
    print('__________')
    print('')


task = input()
print('__________')
print('')


#tasks

if int(task) == 1:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) + int(Y)
    print('__________')
    print('')
    print(X,'+',Y,'=',result)

elif int(task) == 2:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) - int(Y)
    print('__________')
    print('')
    print(X,'-',Y,'=',result)

elif int(task) == 3:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) * int(Y)
    print('__________')
    print('')
    print(X,'*',Y,'=',result)

elif int(task) == 4:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) / int(Y)
    print('__________')
    print('')
    print(X,'/',Y,'=',result)

elif int(task) == 5:
    print('Select X')
    X = input()
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) * int(X)
    print('__________')
    print('')
    print(X,'square =',result)

elif int(task) == 6:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    squarex = int(X) * int(X)
    squarey = int(Y) * int(Y)
    result = squarex * squarey
    print('__________')
    print('')
    print(X,'X square =',squarex)
    print(Y,'Y square =',squarey)
    print(squarex,'*',squarey,'=',result)

elif int(task) == 7:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Calculating...')
    import time
    time.sleep(1)
    squarex = int(X) * int(X)
    squarey = int(Y) * int(Y)
    result = squarex / squarey
    print('__________')
    print('')
    print(X,'X square =',squarex)
    print(Y,'Y square =',squarey)
    print(squarex,'/',squarey,'=',result)

elif int(task) == 8:
    print('Select X')
    X = input()
    print('Calculating...')
    import time
    time.sleep(1)
    import math
    result = math.sqrt(int(X))
    print('__________')
    print('')
    print(X,'root =',result)

elif int(task) == 9:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) * int(Z)
    result = partone + int(X)
    print('__________')
    print('')
    print(X,'+ (',Y,'*',Z,') =')
    print(X,'+',partone,'=',result)

elif int(task) == 10:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) + int(Z)
    result = partone * int(X)
    print('__________')
    print('')
    print(X,'* (',Y,'+',Z,') =')
    print(X,'*',partone,'=',result)

elif int(task) == 11:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) * int(Z)
    result = int(X) - partone
    print('__________')
    print('')
    print(X,'- (',Y,'*',Z,') =')
    print(X,'-',partone,'=',result)

elif int(task) == 12:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) - int(Z)
    result = partone * int(X)
    print('__________')
    print('')
    print(X,'* (',Y,'-',Z,') =')
    print(X,'*',partone,'=',result)

elif int(task) == 13:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) / int(Z)
    result = partone + int(X)
    print('__________')
    print('')
    print(X,'+ (',Y,'/',Z,') =')
    print(X,'+',partone,'=',result)

elif int(task) == 14:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) + int(Z)
    result = int(X) / partone
    print('__________')
    print('')
    print(X,'/ (',Y,'+',Z,') =')
    print(X,'/',partone,'=',result)

elif int(task) == 15:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) + int(Z)
    result = partone / int(X)
    print('__________')
    print('')
    print('(',Y,'+',Z,') /',X,'=')
    print(partone,'/',X,'=',result)

elif int(task) == 16:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) / int(Z)
    result = int(X) - partone
    print('__________')
    print('')
    print(X,'- (',Y,'/','-',Z,') =')
    print(X,'-',partone,'=',result)

elif int(task) == 17:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) - int(Z)
    result = int(X) / partone
    print('__________')
    print('')
    print(X,'/ (',Y,'-',Z,') =')
    print(X,'/',partone,'=',result)

elif int(task) == 18:
    print('Select X')
    X = input()
    print('Select Y')
    Y = input()
    print('Select Z')
    Z = input()
    print('Calculating...')
    import time
    time.sleep(1)
    partone = int(Y) - int(Z)
    result = partone / int(X)
    print('__________')
    print('')
    print('(',Y,'-',Z,') /',X,'=')
    print(partone,'/',X,'=',result)

else:
    print('Invalid operation')



#interesting exit options

print('__________')
print('')
print('To use again re-enter app, type any number to exit app,')
print('or type in 777 to leave this screen on.')
print('__________')
print('')

exitapp = input()
print('__________')
print('')

if int(exitapp) == 1:
    print('Just one...?')
    import time
    time.sleep(2.25)

elif int(exitapp) == 0:
    print('Yeah thats your life... zero...')
    import time
    time.sleep(3.25)

elif int(exitapp) == 777:
    print('Now we are playing the waiting game ;D')
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    import time
    time.sleep(999999)
    print('Your time is up')
    import time
    time.sleep(5)

elif int(exitapp) == 69:
    print('DAMN',exitapp,'?!')
    import time
    time.sleep(1.5)
    print('Cyaa...')
    import time
    time.sleep(2.25)

elif int(exitapp) == 666:
    print('DAMN',exitapp,'?!')
    import time
    time.sleep(1.5)
    print('Cyaa...')
    import time
    time.sleep(2.25)

elif int(exitapp) == 1337:
    print('DAMN',exitapp,'?!')
    import time
    time.sleep(1.5)
    print('Cyaa...')
    import time
    time.sleep(2.25)

elif int(exitapp) == 420:
    print('DAMN',exitapp,'?!')
    import time
    time.sleep(1.5)
    print('Cyaa...')
    import time
    time.sleep(2.25)

elif int(exitapp) == 21:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 4321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 54321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 654321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 7654321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 87654321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) == 987654321:
    print('5')
    import time
    time.sleep(0.5)
    print('4')
    import time
    time.sleep(0.5)
    print('3')
    import time
    time.sleep(0.5)
    print('2')
    import time
    time.sleep(0.5)
    print('1')
    import time
    time.sleep(0.5)
    print('LAUNCH!')
    import time
    time.sleep(5)

elif int(exitapp) > 999:
    print(exitapp,'... Thats a big number son...')
    import time
    time.sleep(2.5)

else:
    print('Bye bye.')
    import time
    time.sleep(3)
Reply
#2
Only import time once at the beginning of the program. Learn about multiline strings:

text = """
This is a multiline string.
It can have more than one line.

It can have blank lines.
It can save you from a bunch of print statements.
"""
print(text)
Learn about functions (see the link in my signature below). Each task can be a function. Learn about dictionaries (there's a tutorial on them in the tutorials section of this forum). You can then put the functions into dictionaries keyed to the menu choices and simplify everything.

Looping forever?

while True:
    # do stuff
    if user_wants_to_quit:
        break
Note that print() is the same as print(''). Also, input accepts a prompt:

print('Select Y')
Y = input()
# or
Y = input('Select Y')
Do int(task) once and assign it to a variable. Use that in your if statements instead of recalculating int(task) every time. As another programmer with the obsessive compulsive feature, I recommend obsessing about efficiency.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
okay thanks, didnt know that i could do text like that...
also, i already saw that loop thing on internet, i looked it up, but i dont quite
understand how does it work, like, how would i implement that in my program now?

EDIT: and decimal numbers, how do they work, i mean, i made it that you can type
in decimal numbers with float() command but what i cant make is that result actually
spells the result correctly, like:

12.3 + 23.5 and id wouldnt break, it would actually do it but in result it would say
35.0 instaed of 35.5, it would allways be X.0...
Reply
#4
It's difficult to say. if you revised your code, it would be helpful what revisions were made.

Given your original post:

if int(task) == 1:
    print('Select X')
    X = input()    # This creates a string
    print('Select Y')
    Y = input()    # This creates a string
    print('Calculating...')
    import time
    time.sleep(1)
    result = int(X) + int(Y)  # This results in the addition of two integers
    print('__________')
    print('')
    print(X,'+',Y,'=',result)
 
You are assigning strings to variables X and Y (the default action of "input()"), then in "result" you are changing them to integers. Integers are positive and negative whole numbers.

All in all, a better way would be:

if int(task) == 1:
    X = float(input('Select X '))
    Y = float(input('Select Y '))
    print('Calculating...')
    # Should be at beginning of file: import time
    time.sleep(1)
    result = X + Y
    print('__________')
    print('')
    print(X,'+',Y,'=',result)    # Not a very pretty output
 
Be aware, however, with 'floats' you may get some surprising answers

>>> 10.1 + 20.2
30.299999999999997
>>>
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
thanks, this helped alot

i still dont understand how to use this, can anyone explain this like you are explaining it to an idiot?
while True:
    # do stuff
    if user_wants_to_quit:
        break
Reply
#6
You start with while <condition/>:. The while statement checks the condition. If the condition evaluates as True, it executes the indented block under the while statement, and then checks the condition again. Since the condition I gave in my example is True (and therefore always evaluates as True), my repeats that code forever. (# do stuff is a place holder for your code). However, the break will skip out of whatever loop it's in. It just skips to the end of the loop and starts executing the code after the loop. The assumption is that during "do stuff' you give the option for the user to stop the program, or that part of the program. If they take that option, you then set user_wants_to_quit to True, and that triggers the break statement, ending the loop. In a menu system like you are programming, one of the options would typically be to quit. So say 86 is the option to quit. You could just test that directly in the while loop:

if int(task) == 86:
    break
You should really learn loops, they are one of the major control structures at the core of programming. In Python you have while loops and for loops. I would recommend doing some searches on 'Python while loop' and 'Python for loop', so you can find some tutorials on them.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
thanks, i made it to loop it and everything :D
Reply


Forum Jump:

User Panel Messages

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