Ok, so. I've programmed, just for fun, a conversion calculator for decimal and binary numbers. Here is the code:
# -*- coding: cp1252 -*-
import sys, os, time
#This is where you convert a binary number into a decimal number.
def binaryToDecimal():
os.system('cls')
while True:
print "To go back to the main menu type 'e' and press enter"
print
print "Binary numbers consist of only '1's and '0's "
binary = raw_input('Type in the binary number: ')
if binary == "e":
mainmenu()
else:
binarylist = list(binary)
no = len(binarylist)
no = no -1
diginum = 0
i = 0
while no > -1:
if binarylist[no] == '1':
kj = 2**i
diginum = diginum + kj
no = no -1
i = i +1
print diginum
raw_input()
#This is where you convert a decimal number into a binary number.
def decimalToBinary():
os.system('cls')
try:
while True:
print "To go back to the main menu type 'e' and press enter"
print
number = raw_input('Type in the digital number: ')
if number == "e":
mainmenu()
else:
number = int(number)
aaa = str(number)
i = 0
numlist = []
while number != 0:
numlist.append(number)
number = number/2
i = i + 1
binarynum = []
i = i-1
while i !=-1:
bd = str(numlist[i])
bdl = list(bd)
bdn = len(bdl)
bdn = bdn - 1
bx = bdl[bdn]
if bx == '0' or bx == '2' or bx == '4' or bx == '6' or bx == '8':
binarynum.append('0')
if bx == '1' or bx == '3' or bx == '5' or bx == '7' or bx == '9':
binarynum.append('1')
i = i - 1
print ''.join(binarynum)
raw_input()
except ValueError:
print "The input should only numbers"
digitalToBinary()
raw_input()
#This is the credits function....
def credit():
os.system('cls')
text = """###########################
Author: Christopher "Kipp" Moore
Date : 12/09/2009
Vision: Binary Conversions v1.0
###########################
"""
for character in text:
sys.stdout.write(character);sys.stdout.flush(),time.sleep(.03),
raw_input()
#Here is the main menu....
def mainmenu():
while True:
os.system('cls')
menu = """##############################
# What Do You Want To Do? #
# #
#1) Convert Decimal ==» Binary #
#2) Convert Binary ==» Decimal #
#3) Credits #
#4) Exit Program #
##############################
Choice [1-4] : """
choice = raw_input(menu)
if choice == "1":
decimalToBinary()
if choice == "2":
binaryToDecimal()
if choice == "3":
credit()
if choice == "4":
print "Good-bye! Thanks for using the converter!"
mainmenu()
Everything runs perfectly, however... When you input selection "4" to exit the program, it just loops back to the menu and doesn't exit the program. Can anybody help me figure out how I get it to not loop the menu for choice #4? It'd be appreciated. Thanks! Bye!