def a1(): while True: base = input("Please input the base (B:inary, D:ecimal, S:top)\n") base = base.upper() if base == 'B': convert = lambda b: str(int(b, 2)) elif base == 'D': convert = lambda d: bin(int(d))[2:] elif base == 'S': break else: print("Your input is not a valid base 10 syntax\n") continue number = input("Please input a number\n") try: print(convert(number)) except ValueError: print("Your input is not a valid base 10 syntax\n") if __name__ == '__a1__': a1() def a2(): x = int(input("Enter a valid base 10 syntax digit(s): ")) if x < 256: print(bin(x)) else: print("Not valid base 10 statement") if __name__ == '__a2__': a2()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question