Created
December 31, 2022 17:01
-
-
Save vachanmn123/0e35cc6c9f1b1b8b0700d1d8941ad954 to your computer and use it in GitHub Desktop.
Python Programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>># First Program | |
>>> print("Hello, World!") | |
Hello, World! | |
>>> myName = input("What is your name? ") | |
What is your name? VachanMN | |
>>> print("Hello, " + myName + ", You will be " + str(int(myAge)+1) + " years old in one year.") | |
Hello, VachanMN, You will be 19 years old in one year. | |
>>> | |
Python 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> # Program to check if a number is positive or negetive | |
>>> number = input("Enter the number: ") | |
Enter the number: -19 | |
>>> if int(number) >= 0: | |
... print("The number is positive") | |
... else: | |
... print("The number is negetive") | |
... | |
The number is negetive | |
>>> | |
Python 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> # Program to check if a number is even or odd | |
>>> number = input("Enter the number: ") | |
Enter the number: 18 | |
>>> if int(number) % 2 == 0: | |
... print("The number is even") | |
... else: | |
... print("The number is odd") | |
... | |
The number is even | |
>>> | |
Python 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> # Pogram to get greatest of 3 numbers | |
>>> number1 = input("Enter the first number: ") | |
Enter the first number: 56 | |
>>> number2 = input("Enter the second number: ") | |
Enter the second number: 63 | |
>>> number3 = input("Enter the third number: ") | |
Enter the third number: 62 | |
>>> largest = 0 | |
>>> if int(number1) > int(number2) and int(number1) > int(number3): | |
... largest = number1 | |
... elif int(number2) > int(number3): | |
... largest = number2 | |
... else: | |
... largest = number3 | |
... | |
>>> print(largest + " is the largest of the three numbers.") | |
63 is the largest of the three numbers. | |
>>> | |
Python 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> # Python program to check grade of student.(if-elif-else). | |
>>> grade = input("Enter the grade of the student(A, B, C, D, E, F): ") | |
Enter the grade of the student(A, B, C, D, E, F): A | |
>>> if grade == "A": | |
... print("Excellent") | |
... elif grade == "B": | |
... print("Good") | |
... elif grade == "C": | |
... print("Needs improvement") | |
... elif grade == "D" or grade == "E": | |
... print("Needs to work hard") | |
... elif grade == "F": | |
... print("FAIL") | |
... else: | |
... print("INVALID GRADE") | |
... | |
Excellent | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment