~yacinechaouche/+junk/BZR

« back to all changes in this revision

Viewing changes to CODE/FB/binaryconversion.py

  • Committer: yacinechaouche at yahoo
  • Date: 2015-01-14 22:23:03 UTC
  • Revision ID: yacinechaouche@yahoo.com-20150114222303-6gbtqqxii717vyka
Ajout de CODE et PROD. Il faudra ensuite ajouter ce qu'il y avait dan TMP

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
#!/usr/bin/python
 
4
 
 
5
def sel_option():
 
6
        # Welcome message 
 
7
        print "Hello \n "
 
8
        print "1. Decimal to Binary Conversion. \n"
 
9
        print "2. Binary to Decimal Conversion. \n"
 
10
        print "3. About. \n"
 
11
        print "4. Exit. \n"
 
12
        choice=raw_input("Enter No. of Your Choice: ")
 
13
 
 
14
        #Do Decimal to Binary Conversion
 
15
        if choice == "1" :
 
16
           print  "1. Decimal to Binary Conversion. \n"
 
17
           num=raw_input("Enter the decimal number: ")
 
18
           num=int(num)
 
19
           binary=bin(num)
 
20
           print "The binary form of the number is: %s " % binary[2:]
 
21
           do_exit()
 
22
 
 
23
        # Do Binary to Decimal Conversion.      
 
24
        elif choice == "2":
 
25
                print "2. Binary to Decimal Conversion \n"
 
26
                binput=raw_input ("Enter the binary number: ")
 
27
                dec=int(str(binput),2)
 
28
                print "The Decimal form of the number is: %s \n " % (dec)
 
29
                do_exit()
 
30
 
 
31
        # Display the About page.
 
32
        elif  choice == "3":
 
33
                print " Add about information here. \n"
 
34
                do_exit()
 
35
 
 
36
        # Exit
 
37
        elif choice == "4":
 
38
                print " Good Bye "
 
39
                exit (0)
 
40
 
 
41
        # If no option matches, retry
 
42
        else:
 
43
                print " Select the options 1 to 4 \n"
 
44
                sel_option()
 
45
 
 
46
def do_exit():
 
47
        ans=raw_input("Do you want to exit (y/n): ? ")
 
48
        ans=ans.lower()
 
49
        if ans == "y":
 
50
                print "Good Bye"
 
51
        elif ans == "n" :       
 
52
                sel_option()
 
53
        else:
 
54
                print " Enter y or n \n "
 
55
                sel_option()
 
56
 
 
57
sel_option()
 
58