MisterTootor M.S., B.S., A.S., A.S.B
I'm a paragraph. Click here to add your own text and edit me. It's easy.
​
using System;
​
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World!"); // relies on "using
System;"
Console.Write("This is");
Console.Write("... my first program!\n");
System.Console.WriteLine("Goodbye World!"); // no "using" statement
required
}
}
​
​
The above code displays the following text:
​
​
Hello World!
This is... my first program!
Goodbye World!
The example program below shows a couple of ways to output text:
# This function adds two numbers
def add(x, y):
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two numbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
# take input from the user
choice = input("Enter choice(1/2/3/4): ")
# check if choice is one of the four options
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
# check if user wants another calculation
# break the while loop if answer is no
next_calculation = input("Let's do next calculation? (yes/no): ")
if next_calculation == "no":
break
else:
print("Invalid Input")
​
Output:
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0
Let's do next calculation? (yes/no): no
How to make a basic calculator
​
# Example: For positive numbers
# Note: change this value for a different result
num = 8
# To take the input from the user
#num = float(input('Enter a number: '))
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
​
Output:
​
​​The square root of 8.000 is 2.828
# Python Program to calculate the square root - # https://www.programiz.com/python-programming/examples
# Python Program to find the area of triangle
If a, b and c are three sides of a triangle. Then,
s = (a+b+c)/2
area = √(s(s-a)*(s-b)*(s-c))
Source Code
a = 5
b = 6
c = 7
# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
Output
The area of the triangle is 14.70
Ask Python - Quiz - https://www.askpython.com/python/examples/easy-games-in-python
print('Welcome to AskPython Quiz')
answer=input('Are you ready to play the Quiz ? (yes/no) :')
score=0
total_questions=3
if answer.lower()=='yes':
answer=input('Question 1: What is your Favourite programming language?')
if answer.lower()=='python':
score += 1
print('correct')
else:
print('Wrong Answer :(')
answer=input('Question 2: Do you follow any author on AskPython? ')
if answer.lower()=='yes':
score += 1
print('correct')
else:
print('Wrong Answer :(')
answer=input('Question 3: What is the name of your favourite website for learning Python?')
if answer.lower()=='askpython':
score += 1
print('correct')
else:
print('Wrong Answer :(')
print('Thankyou for Playing this small quiz game, you attempted',score,"questions correctly!")
mark=(score/total_questions)*100
print('Marks obtained:',mark)
print('BYE!')
Welcome to AskPython Quiz
Are you ready to play the Quiz ? (yes/no) :yes
Question 1: What is your Favourite programming language?
=== Session Ended. Please Run the code again ===
Output: