Total Pageviews

Saturday, April 18, 2020

INPUT AND OUTPUT ( PYTHON )


PYTHON VARIABLE AND OPERATOR

1. BASIC INPUT OUTPUT -  CLICK
2. ADDITION - CLICK
3. BASIC - CLICK

1)

a = 5
print(a)

Output:

5

2)

a = 5
print("A =", a)

Output:

A = 5

3)

a = 5
b = 7
c = a + b

print(c)

Output:

12

4)

a = 5
b = 7
c = a + b

print("sum =", c)

Output:

sum = 12

5) Sum and Average of Two Numbers

a = 5
b = 7

c = a + b
d = c / 2

print("sum =", c)
print("Average =", d)

Output:

sum = 12
Average = 6.0

6) Sum and Average of 3 Numbers

a = 2
b = 4
c = 12

s = a + b + c
av = s / 3

print("sum =", s)
print("average =", av)

Output:

sum = 18
average = 6.0

7) WAP in Python to Do Arithmetic Operations

a = 12
b = 4

sum = a + b
sub = a - b
mul = a * b
div = a / b

print("sum =", sum)
print("sub =", sub)
print("mul =", mul)
print("div =", div)

Output:

sum = 16
sub = 8
mul = 48
div = 3.0

 

 

 

 

8) Division (/) and Floor Division (//)

a = 5
b = 2

c = a / b
d = a // b

print("Division =", c)
print("Floor Division =", d)

Output:

Division = 2.5
Floor Division = 2

9) Exponent Operator (**)

a = 5
b = 2

c = a ** b

print(c)

Output:

25

or

a = 5
b = 2

c = b ** a

print(c)

Output:

32

10) Find First and Last Digit of a Two-Digit Number

n = 37

a = n % 10
b = n // 10

print("Last Digit =", a)
print("First Digit =", b)

Output:

Last Digit = 7
First Digit = 3

11) Sum of Digits of a Two-Digit Number

n = 37

a = n % 10
b = n // 10

sum = a + b

print("Sum of digits =", sum)

Output:

Sum of digits = 10

11) Input Value from User and Display

a = input("Enter a value: ")

print(a)

Output:

Enter a value: 5
5

12) Input Your Name and Surname and Display

name = input("Enter your name: ")
sname = input("Enter your surname: ")

print("Name =", name)
print("Surname =", sname)

Output:

Enter your name: Bijan
Enter your surname: Paul

Name = Bijan
Surname = Paul

13) String Concatenation Using +

a = input("Enter a value: ")
b = input("Enter second value: ")

c = a + b

print(c)

Output:

Enter a value: 3
Enter second value: 5

35

Note: + acts as a Concatenation Operator for strings.


14) Addition of Two Numbers Using User Input

a = int(input("Enter a value: "))
b = int(input("Enter 2nd value: "))

c = a + b

print(c)

Output:

Enter a value: 3
Enter 2nd value: 5

8

15) Sum of Two Float Numbers

a = float(input("Enter 1st float number: "))
b = float(input("Enter 2nd float number: "))

c = a + b

print(c)

Output:

Enter 1st float number: 5.5
Enter 2nd float number: 2.5

8.0

16) Sum and Average of Three Integers

a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
c = int(input("Enter 3rd number: "))

sum = a + b + c
avg = sum / 3

print("Sum =", sum)
print("Average =", avg)

Output:

Enter 1st number: 10
Enter 2nd number: 20
Enter 3rd number: 30

Sum = 60
Average = 20.0

17) Centigrade to Fahrenheit

Formula:

F=9C5+32F = \frac{9C}{5} + 32F=59C+32

c = float(input("Enter the centigrade value: "))

f = ((9 * c) / 5) + 32

print("Fahrenheit value =", f)

Output:

Enter the centigrade value: 25

Fahrenheit value = 77.0

18) Fahrenheit to Centigrade

Formula:

C=5(F−32)9C = \frac{5(F - 32)}{9}C=95(F32)

f = float(input("Enter the temperature in °F: "))

c = (5 * (f - 32)) / 9

print("Centigrade value =", c)

Output:

Enter the temperature in °F: 98.6

Centigrade value = 37.0

19) Convert Hours, Minutes and Seconds into Total Seconds

h = int(input("Enter hours: "))
m = int(input("Enter minutes: "))
s = int(input("Enter seconds: "))

time = (h * 60 * 60) + (m * 60) + s

print("Time in seconds =", time)

Output:

Enter hours: 1
Enter minutes: 20
Enter seconds: 30

Time in seconds = 4830

20) Convert Years, Months, Weeks and Days into Total Days

year = int(input("Enter years: "))
month = int(input("Enter months: "))
week = int(input("Enter weeks: "))
day = int(input("Enter days: "))

total_days = (year * 365) + (month * 30) + (week * 7) + day

print("Total days =", total_days)

Output:

Enter years: 1
Enter months: 2
Enter weeks: 1
Enter days: 3

Total days = 435

 

 

 

 1. Addition of Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

sum = a + b

print("Sum =", sum)


2. Subtraction of Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

difference = a - b

print("Difference =", difference)


3. Multiplication of Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

product = a * b

print("Product =", product)


4. Division of Two Numbers

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

quotient = a / b

print("Quotient =", quotient)


5. Find Remainder

a = int(input("Enter dividend: "))
b = int(input("Enter divisor: "))

remainder = a % b

print("Remainder =", remainder)


6. Calculate Square of a Number

n = int(input("Enter a number: "))

square = n * n

print("Square =", square)


7. Calculate Cube of a Number

n = int(input("Enter a number: "))

cube = n ** 3

print("Cube =", cube)


8. Calculate Area of Rectangle

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

area = length * breadth

print("Area =", area)


9. Calculate Perimeter of Rectangle

length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))

perimeter = 2 * (length + breadth)

print("Perimeter =", perimeter)


10. Calculate Area of Circle

radius = float(input("Enter radius: "))

area = 3.14 * radius * radius

print("Area =", area)


11. Calculate Circumference of Circle

radius = float(input("Enter radius: "))

circumference = 2 * 3.14 * radius

print("Circumference =", circumference)


12. Calculate Simple Interest

p = float(input("Enter Principal: "))
r = float(input("Enter Rate: "))
t = float(input("Enter Time: "))

si = (p * r * t) / 100

print("Simple Interest =", si)


13. Calculate Average of Three Numbers

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

average = (a + b + c) / 3

print("Average =", average)


14. Convert Celsius to Fahrenheit

celsius = float(input("Enter temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print("Fahrenheit =", fahrenheit)


15. Convert Fahrenheit to Celsius

fahrenheit = float(input("Enter temperature in Fahrenheit: "))

celsius = (fahrenheit - 32) * 5/9

print("Celsius =", celsius)


16. Calculate Percentage of Marks

m1 = float(input("Enter marks of Subject 1: "))
m2 = float(input("Enter marks of Subject 2: "))
m3 = float(input("Enter marks of Subject 3: "))
m4 = float(input("Enter marks of Subject 4: "))
m5 = float(input("Enter marks of Subject 5: "))

total = m1 + m2 + m3 + m4 + m5
percentage = total / 5

print("Percentage =", percentage)


17. Calculate Discount Amount

price = float(input("Enter product price: "))
discount = float(input("Enter discount percentage: "))

discount_amount = (price * discount) / 100

print("Discount Amount =", discount_amount)


18. Calculate Final Price After Discount

price = float(input("Enter product price: "))
discount = float(input("Enter discount percentage: "))

final_price = price - (price * discount / 100)

print("Final Price =", final_price)


19. Swap Two Numbers Using Arithmetic Operations

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

a = a + b
b = a - b
a = a - b

print("After Swapping:")
print("a =", a)
print("b =", b)


20. Calculate Power of a Number

base = int(input("Enter base: "))
exponent = int(input("Enter exponent: "))

result = base ** exponent

print("Result =", result)

 

Monday, April 13, 2020

python program code example8. while loop in python

python program code
example8. while loop in python


python program code example7. for loop in python

python program code
example7. for loop in python




python program code example 6. nested if positive negative zero checking

python program code
 example 6. nested if positive negative zero checking


python program code example 5. if - else positive negative number checking



python program code
example 5. if - else positive negative number checking





python program code example 4. if - else , larger of two numbers

python program code

example 4. if - else , larger of two numbers


python program code example 3. basic arithmetic operator

python program code

example 3. basic arithmetic operator



python program code example2. addition of two variable

python program code
example2. addition of two variable

python program code example 1. input integer value and print.

python program code
example 1. input integer value and print.


Saturday, April 11, 2020

TRIANGLE PATTERN PRINT IN VISUAL BASIC 6

TRIANGLE  PATTERN PRINT  IN VISUAL BASIC 6


AAAAA
   BBBB
      CCC
        DD
           E


TRIANGLE PATTERN PRINT USING '*' IN VISUAL BASIC 6

TRIANGLE  PATTERN PRINT USING '*' IN VISUAL BASIC 6


     *
   **
 ***
****


TRIANGLE PATTERN PRINT IN VISUAL BASIC 6

TRIANGLE  PATTERN PRINT IN VISUAL BASIC 6


ABCDE
ABCD
ABC
AB
A


TRIANGLE PATTERN PRINT IN VISUAL BASIC 6

TRIANGLE  PATTERN PRINT IN VISUAL BASIC 6


EEEEE
DDDD
CCC
BB
A



TRIANGLE PATTERN PRINT IN VISUAL BASIC 6

TRIANGLE  PATTERN PRINT IN VISUAL BASIC 6
A
BB
CCC
DDDD
EEEEEE
FFFFFFFF


TRIANGLE PATTERN IN VISUAL BASIC 6

TRIANGLE PATTERN IN VISUAL BASIC 6

A
AB
ABC
ABCD
ABCDE
ABCDEF



PATTERN PRINT IN VISUAL BASIC 6

PATTERN PRINT IN VISUAL BASIC 6

ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH



PATTERN PRINT IN VISUAL BASIC 6

PATTERN PRINT IN VISUAL BASIC 6

AAAAA
BBBBB
CCCCC
DDDDD
EEEEE



PATTERN PRINT IN VISUAL BASIC 6

PATTERN PRINT IN VISUAL BASIC 6

55555
4444
333
22
1



PATTERN PRINT IN VISUAL BASIC 6

PATTERN PRINT IN VISUAL BASIC 6

55555
44444
33333
22222
11111