def Solution(): inputs = [] for i in range(3): var = input('Please enter integer ' + str(i+1)) while not float(var)%1==0: var = input('Input type wrong. Please enter INTEGER ' + str(i+1)) if var=='q': break inputs.append(var) print('You entered integers ' + str(inputs[0]) + ', ' + str(inputs[1]) + ' and ' + str(inputs[2]) + '. These values are:' ) if inputs[0]==inputs[1] and inputs[1]==inputs[2]: print('equal') else: print('not equal')
def main(): courses = [] students = {} grades = {} while True: s = input() if s == "Courses": d = 1 elif s == "Students": d = 2 elif s == "Grades": d = 3 elif s == "EndOfInput": break else: s = s.split("~") if d == 1: courses.append(s) elif d == 2: students[s[0]] = s[1] grades[s[0]] = [] elif d == 3: grades[s[-2]].append(s[-1]) points = {"A":10, "AB":9, "B":8, "BC":7, "C":6, "CD":5, "D":4} for idx in sorted(grades): p = [points[x] for x in grades[idx]] n = len(p) or 1 marks = str(round(sum(p)/n,2)) if p else "0" d = [idx,students[idx],marks] print("~".join(d))
Why not guess which number is thought in Fish mind8 Whoa!Are you a worm in my heart Well,no prize Game over >>> ============= RESTART: D:/Python/2019-7-29-xiaojiayu-video-3.py ============= ---------I love fish workplace----------- Why not guess which number is thought in Fish mind6 Wrong!Is's 8 Game over >>> ##the built-in function >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. >>> help int SyntaxError: invalid syntax >>> help(int) >>> help(help) Help on _Helper in module _sitebuiltins object:
Python 3.2.3 (default, Sep 25 2013, 18:25:56) [GCC 4.6.3] on linux2 Type "copyright", "credits" or "license()" for more information. ==== No Subprocess ==== >>> dir(__bultins__) Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> dir(__bultins__) NameError: name '__bultins__' is not defined >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] >>> help(input) Help on built-in function input in module builtins: input(...) input([prompt]) -> string Read a string from standard input. The trailing newline is stripped. If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError. On Unix, GNU readline is used if enabled. The prompt string, if given, is printed without a trailing newline before reading. >>> help(set) Help on class set in module builtins: class set(object) | set() -> new empty set object | set(iterable) -> new set object | | Build an unordered collection of unique elements. |
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> help(inpit) Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> help(inpit) NameError: name 'inpit' is not defined >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. >>> input("input your name:") input your name:123 '123' >>> user=input("name") name123 >>> user '123' >>> "i like %s" % "Python" 'i like Python' >>> "i like %s" % "Pascal" # %s为一个占位符,%后接与之对应类型的对象,常用的还有%d、%f 'i like Pascal' >>> a="%d years old" % 22
which by default comes from the keyboard. These functions are : 1. raw_input 2. input The raw_input Function: *********************** The raw_input([prompt]) function reads one line from standard input and returns it as a string (removing the trailing newline). #!/usr/bin/python str = input("Enter your input: "); print "Received input is : ", str This prompts you to enter any string and it would display same string on the screen. When I typed "Hello Python!", its output is like this − Enter your input: Hello Python Received input is : Hello Python --------------------------------------------------------- The input Function: ******************* The input([prompt]) function is equivalent to raw_input, except that it assumes the input is a valid Python expression and returns the evaluated result to you. #!/usr/bin/python
True >>> num_names = len(names) >>> isinstance(num_names,list) False >>> dir <built-in function dir> >>> dir(_builtins_) Traceback (most recent call last): File "<pyshell#50>", line 1, in <module> dir(_builtins_) NameError: name '_builtins_' is not defined >>> dir(__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'] >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. >>> print(movies) ['The Holy Grail', 1975, 'Terry Jones & Terry Gilliam', 91, ['Graham Chapman', ['Michael Palin', 'John Cleese', 'Terry Gilliam', 'Eric Idle', 'Terry Jones']]] >>> for each_item in movies: if(isinstance(each_item,list)): for each_item2 in each_item: print(each_item2)
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> species = input("Please enter species: ") Please enter species: Python curtus >>> species 'Python curtus' >>> "Computer' + 'Science' SyntaxError: EOL while scanning string literal >>> 'Computer' + 'Science' 'ComputerScience' >>> 'Computer' + ' Science' 'Computer Science' >>> 'Darwin\'s' "Darwin's" >>> 'H2O' * 3 'H2OH2OH2O' >>> 'CO2' * 00 '' >>> 'They\'ll hibernate uring the winter.' "They'll hibernate uring the winter." >>> '\"Absolutely not,\" he said.' '"Absolutely not," he said.' >>> '\"He said,\'Absolutely not,\"\' recalled Mel.' '"He said,\'Absolutely not,"\' recalled Mel.' >>> '"He said,'Absolutely not,'" recalled Mel.' SyntaxError: invalid syntax >>> '"He said,\'Absolutely not,'"recalled Mel.' SyntaxError: EOL while scanning string literal >>> '"He said,\'Absolutely not,\'"recalled Mel.' '"He said,\'Absolutely not,\'"recalled Mel.'
raw_input(...) raw_input([prompt]) -> string Read a string from standard input. The trailing newline is stripped. If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError. On Unix, GNU readline is used if enabled. The prompt string, if given, is printed without a trailing newline before reading. >>> ================================ RESTART ================================ >>> What is your name? Jatin Hello Mr Jatin >>> help(input) Help on built-in function input in module __builtin__: input(...) input([prompt]) -> value Equivalent to eval(raw_input(prompt)). >>> ================================ RESTART ================================ >>> What is your name? Jatin Hello Mr Jatin What is your age? 35 so your age is 35 >>> ================================ RESTART ================================ >>> What is your name? Jatin Hello Mr Jatin
Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import biltins ModuleNotFoundError: No module named 'biltins' >>> import builtins >>> print(dir(builtin) dir(keywoeds SyntaxError: invalid syntax >>> a=input('enter name') enter namePradeep Sharma >>> print(a) Pradeep Sharma >>> help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments:
4485873424 >>> hex(4485873424) '0x10b60ff10' >>> id(a) == id(c) False >>> input.__doc__ 'Read a string from standard input. The trailing newline is stripped.\n\nThe prompt string, if given, is printed to standard output without a\ntrailing newline before reading input.\n\nIf the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\nOn *nix systems, readline is used if available.' >>> print(input.__doc__) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. >>> input("Enter your name: ") Enter your name: Anmol 'Anmol' >>> input("Enter a number: ") Enter a number: 10 '10' >>> x = input("Enter a number: ") Enter a number: 10 >>> print(x) 10 >>> y = input("Enter a number: ") Enter a number: 20 >>> print(y) 20 >>> type(x) <class 'str'>
raw_input([prompt]) function reads one line from standard input and returns it as a string(removing the trailing newline). # !/usr/bin/python str = input("Enter your input: "); print "Received input is : ", str This prompts you to enter any string and it would display same string on
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> Number =input ("Enter your number") Enter your number12 >>> Number '12' >>> >>> Number = int (input ("Enter your number")) Enter your number12 >>> Number 12 >>> help(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. >>> hrlp (str) Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> hrlp (str) NameError: name 'hrlp' is not defined >>> import os >>> os.system('cls') 0
<built-in method title of str object at 0x036A6860> >>> name.title() 'Andrea' >>> ============ RESTART: C:/Users/Andre/Desktop/code/number guess.py ============ 3 >>> ============ RESTART: C:/Users/Andre/Desktop/code/number guess.py ============ 7 >>> ============ RESTART: C:/Users/Andre/Desktop/code/number guess.py ============ 8 enter your guess Traceback (most recent call last): File "C:/Users/Andre/Desktop/code/number guess.py", line 9, in <module> guess = int(input('enter your guess ')) ValueError: invalid literal for int() with base 10: '' >>> ============ RESTART: C:/Users/Andre/Desktop/code/number guess.py ============ 5 enter your guess 4 enter your guess 0 >>> 8 8 >>> from random import randint >>> randint(1, 9) 9 >>> randint(1, 9) 7 >>> randint(1, 9) 7