Page 118 - ComputerGenius_V2.1_Class8
P. 118

Creator Guido van Rossum named the language 'Python', after the popular
                     BBC comedy series  "Monty  Python's  Flying  Circus”.  He wanted  to  select  a
                     name that was a little bit mysterious and unpredictable.





                  Input Statement in Python

                  In python, to take input from the user we use input() function. This input() function prompts the
                  user to enter data.

                  Syntax:
                    input([prompt])
                  This input() considers everything as string. Whether the user enters a number or a string but the
                  input() treats them as strings only. So, in order to consider the input value as other than string, we
                  have to convert it into other datatype.
                  For example:

                    A=input("Enter your Name") #Here the input entered is String
                    B=input("Enter  your marks")  ' ' 'Here  the input is again  String,  but we
                    cannot do calculations on String. So it is converted into other data types.' ' '
                  Thus, the changed statement will be:

                    B=int(input("Enter your Marks") ) #To enter integer data values.
                    C=float(input("Enter your Price of the item")) #To input decimal values.

                  Output Statement in Python


                  The print() outputs a complete line and then moves to the next line for subsequent output.
                  Syntax:
                    print(value1, value2,....., valueN)
                  For example:

                    a=10
                    print("value of a",a)
                  Example 1: Input and Output statements in Python

                  Program:                                                     Output:
                    #Python program to swap two variable values
                                                                                 enter first number 23
                    num1=int(input("enter first number"))
                                                                                 enter second number 45
                    num2=int(input("enter second number"))
                                                                                 Now the value of num1 45
                    temp=num1
                                                                                 Now the value of num2 23
                    num1=num2
                    num2=temp
                    print("Now the value of num1",num1)

                    print("Now the value of num2",num2)


                       116   Computer Genius (V2.1)-VIII
   113   114   115   116   117   118   119   120   121   122   123