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...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#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:

1
2
3
4
5
6
7
8
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?

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

1
2
3
4
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
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:

1
2
3
4
5
6
7
8
9
10
11
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

1
2
3
>>> 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?
1
2
3
4
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:

1
2
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