Last active
March 17, 2018 14:33
-
-
Save chauhan-tarun/02702b4411fc9f336dcdd584fcd726cd to your computer and use it in GitHub Desktop.
Exercise answers of video tutorial "Python 3 for beginners - #4. Inputs" by TheTechnicalFist : https://youtu.be/Lmrpdmk9Hxo
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
# Take two global values to perform all operations in this program | |
value1 = eval(input("Enter first integer value : ")) | |
value2 = eval(input("Enter second integer value : ")) | |
# Question 1. Create a program to Subtract two or more values | |
print(value1, " - ", value2, " = ", value1 - value2) | |
# Question 2. Create a program to Multiply two or more values | |
print(value1, " * ", value2, " = ", value1 * value2) | |
# Question 3. Create a program to Divide two or more values | |
print(value1, " / ", value2, " = ", value1 / value2) | |
# Question 4. Create a program to find Module between two values | |
print("Module of ", value1, " and ", value2, " is : ", value1 % value2) | |
# Question 5. Create a program to find power of value | |
print(value2, " power of ", value1, " is : ", value1 ** value2) | |
# Question 6. Create a program to swap two numbers using Third variable | |
print("--------Swapping using 3rd variable--------") | |
print("Values before swap - \nA : ", value1, "\nB : ", value2) | |
# Take backup of value 1 | |
thirdVariable = value1 | |
# Add value2 into value1 | |
value1 = value2 | |
# Add thirdVariable i.e. value1 into value2 | |
value2 = thirdVariable | |
print("Values after swap - \nA : ", value1, "\nB : ", value2) | |
# Question 7. Create a program to swap two numbers without using Third variable | |
print("--------Swapping without using 3rd variable--------") | |
print("Values before swap - \nA : ", value1, "\nB : ", value2) | |
# Add sum of value1 and value2 into value1 | |
value1 = value1 + value2 | |
# Subtract value1(i.e. sum of both values) by value2 | |
value2 = value1 - value2 | |
# Subtract value1(i.e. sum of both values) by value2(i.e. original value of value1) | |
value1 = value1 - value2 | |
print("Values after swap - \nA : ", value1, "\nB : ", value2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment