Author Topic: Clear screen python  (Read 1415 times)

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #30 on: August 29, 2012, 03:27:15 pm »
Final question (for now :P)

Is there a way to return to a previous menu. Like if I have a redirect to a different script is there a way to return to the first one?

rhodysurf

  • Noob
  • *
  • Posts: 31
  • Reputation: 4
  • Computers: Lenovo Thinkpad Edge running Windows 8, Ubuntu, and mac osx in a vm
  • iDevices: Iphone 4 iOS 5.1.1
Re: Clear screen python
« Reply #31 on: August 29, 2012, 04:15:48 pm »
You could make the menu you called a function, then just use a conditional to recall the menu function after your action.

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #32 on: August 29, 2012, 05:53:25 pm »
Oh yah wow I am not on top of it. Thats for sure.

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4016
  • Reputation: 216
  • Badges:
Re: Clear screen python
« Reply #33 on: August 29, 2012, 06:02:19 pm »
Just make your main screen into a function, or put it in a while loop

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #34 on: August 29, 2012, 06:09:51 pm »
But in making the main screen a function I had to make a start-up script to run the entire thing. I think I've got it figured out now except for the fact that if you dont enter a one of the specified numbers it quits.

Don't like seeing ads? Click here to register!

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4016
  • Reputation: 216
  • Badges:
Re: Clear screen python
« Reply #35 on: August 29, 2012, 06:29:39 pm »
It seems you are making this a lot harder than you need to. Why not just declare the functions inside the actual program and not in all these random files?

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #36 on: August 29, 2012, 06:31:48 pm »
Because I have no idea what I'm doing.

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Clear screen python
« Reply #37 on: August 29, 2012, 06:32:49 pm »
Then take a step back

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4016
  • Reputation: 216
  • Badges:
Re: Clear screen python
« Reply #38 on: August 29, 2012, 06:36:30 pm »
Read up some more on functions.

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #39 on: August 29, 2012, 06:42:02 pm »
Here's what I'm doing.

#Main screen for Python Math

def main():

   import os
   import time
   import basic
   os.system("clear")

   print ("Welcome to Python Math")
   print ("")
   time.sleep(1)
   print ("[1] Basic Math")
   print ("[2] Advanced Math")
   print ("[3] Exit")
   print ("")

   a = input("Please chose an option: ")

   if a == 1:
    basic.basic()

   if a == 3:
    exit()


That's the main screen to chose whether or not to go into the basic or advanced. Im making the advanced later.

#basic math

def basic():

  import os
  import time
  import main
  import math
  os.system("clear")

  print ("Welcome to Python Math")
  print ("")
  time.sleep(1)
  print ("[1] 2 Digit Addition")
  print ("[2] 2 Digit Subtraction")
  print ("[3] 2 Digit Multiplication")
  print ("[4] 2 Digit Division")
  print ("[5] 3 Digit Addition")
  print ("[6] 3 Digit Subtraction")
  print ("[7] 3 Digit Multiplication")
  print ("[8] 3 Digit Division")
  print ("[9] Return")
  print ("")
  time.sleep(3)
  a = input("Chose which function to use: ")

  if a == 1:
     math.add()

  if a == 2:
     math.sub()

  if a == 3:
     math.mult()

  if a == 4:
     math.div()

  if a == 5:
     math.addtwo()

  if a == 6:
     math.subtwo()

  if a == 7:
     math.multtwo()

  if a == 8:
     math.divtwo()

  if a == 9:
     main.main()


That's the script when you go to the basic screen where you chose the math problem to do.

#python addition script
def add():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    print "Your answer is: ",(a+b)

#python subtraction script
def sub():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    print "Your answer is: ",(a-b)

#python multiplication script
def mult():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    print "Your answer is: ",(a*b)

#python division script
def div():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    print "Your answer is: ",(a/b)

#python addition script
def addtwo():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    c = float(raw_input("Enter the third number: "))
    print "Your answer is: ",(a+b+c)

#python subtraction script
def subtwo():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    c = float(raw_input("Enter the third number: "))
    print "Your answer is: ",(a-b-c)

#python multiplication script
def multtwo():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    c = float(raw_input("Enter the third number: "))
    print "Your answer is: ",(a*b*c)

#python division script
def divtwo():
    a = float(raw_input("Enter the first number: "))
    b = float(raw_input("Enter the second number: "))
    c = float(raw_input("Enter the third number: "))
    print "Your answer is: ",(a/b/c)


Thats the math for all the basic problems.

#Python Start

import main

main.main()


That's the start up. I have no idea how to make it simpler.

Don't like seeing ads? Click here to register!

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4016
  • Reputation: 216
  • Badges:
Re: Clear screen python
« Reply #40 on: August 29, 2012, 06:45:04 pm »
Do all the imports outside of a function. Put *all* of your functions inside the same file. That way you dont have to import it. Then at the very bottom just call the main function, or put the content of your main function into an infinite loop with an exit condition(while input != 'exit':) or something of the kind.

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Clear screen python
« Reply #41 on: August 29, 2012, 06:47:13 pm »
I'll let a12 make the bigger fixes but does an elseif (else if) exist? Cause I know that would be more effecient than multiple if statements checking the input. Also, you have to sanitize input too. But that's like finishing touches...just stuff to keep in mind ;)

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Clear screen python
« Reply #42 on: August 29, 2012, 06:49:45 pm »
But won't that just be another file or then would you put all the other things in a single file?

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4016
  • Reputation: 216
  • Badges:
Re: Clear screen python
« Reply #43 on: August 29, 2012, 06:49:50 pm »
Yeah, its elif.

UberN00b

  • Hero Member
  • *****
  • Posts: 523
  • Reputation: 22
  • Perfection is a process.
  • Computers: em250-kav60 netbook
  • iDevices: iPhone 4
Re: Clear screen python
« Reply #44 on: August 29, 2012, 08:44:54 pm »
My NewBoston tutorials are collecting dust, but from what I think I remember it looks like your making a basic math tutorial. Correct? Calculator?

Edit: Durrh! Nvm, I missed "#Basic Math", the very first line. Lol
« Last Edit: August 29, 2012, 08:55:29 pm by UberN00b »
A million strands of spiderwebs weaved to make my vest!