diff --git a/README.md b/README.md index 74422a9..90a808b 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,10 @@ Reference Links:- - Project 3 - Quiz - Project 4 - Clock - Project 5 - QR Code +- Project 6 - Pronic Number +- Project 7 - Reverse a Number +- Project 8 - Perfect Number +- Project 9 - Display Calender +- Project 10 - Binary to Decimal Converter +- Project 11 - BMI Calculator +- Project 12 - Image to PDF Converter diff --git a/binary_to_decimal/binary-decimal.py b/binary_to_decimal/binary-decimal.py new file mode 100644 index 0000000..03ade00 --- /dev/null +++ b/binary_to_decimal/binary-decimal.py @@ -0,0 +1,12 @@ +print("Enter the Binary Number: ") +bnum = int(input()) + +dnum = 0 +i = 1 +while bnum!=0: + rem = bnum%10 + dnum = dnum + (rem*i) + i = i*2 + bnum = int(bnum/10) + +print("\nEquivalent Decimal Value = ", dnum) \ No newline at end of file diff --git a/display_calender/display_calender.py b/display_calender/display_calender.py new file mode 100644 index 0000000..2721fbf --- /dev/null +++ b/display_calender/display_calender.py @@ -0,0 +1,10 @@ +import calendar + +print("Enter Year: ") +yy = input() +print("\nEnter Month Number (1-12): ") +mm = input() + +y = int(yy) +m = int(mm) +print("\n", calendar.month(y, m)) \ No newline at end of file diff --git a/perfect_number/perfect_number.py b/perfect_number/perfect_number.py new file mode 100644 index 0000000..d07fd2e --- /dev/null +++ b/perfect_number/perfect_number.py @@ -0,0 +1,10 @@ +print("Enter the Number:") +num = int(input()) +sum = 0 +for i in range(1, num): + if num%i==0: + sum = sum+i +if num==sum: + print("It is a Perfect Number") +else: + print("It is not a Perfect Number") \ No newline at end of file diff --git a/project binary/binary.py b/project binary/binary.py new file mode 100644 index 0000000..4c6ee7b --- /dev/null +++ b/project binary/binary.py @@ -0,0 +1,43 @@ +# Recursive Binary Search algorithm in Python + +def binarySearch(array, x, low, high): + +if high >= low: + +mid = low + (high - low)//2 + +# If found at mid, return the value + +if array[mid] == x: + +return mid + +# Search the first half + +elif array[mid] > x: + +return binarySearch(array, x, low, mid-1) + +# Search the second half + +else: + +return binarySearch(array, x, mid + 1, high) + +else: + +return -1 + +array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +x = int(input("Enter a number between 1 and 10:")) + +result = binarySearch(array, x, 0, len(array)-1) + +if result != -1: + +print("Element is present at position" + str(result)) + +else: + +print("Element not found") diff --git a/project guess the number game/main.py b/project guess the number game/main.py new file mode 100644 index 0000000..4bee4d4 --- /dev/null +++ b/project guess the number game/main.py @@ -0,0 +1,11 @@ +#Guess the Number Game +import random +for i in range(0,3): + number = random.randint(1,10) + user = int(input("Guess the number ")) + if user == number: + print("Hurray!!") + print(f"you guessed the number right it's {number}") + break + if user != number: + print(f"Your guess is incorrect the number is {number}") \ No newline at end of file diff --git a/project image to pdf converter/main.py b/project image to pdf converter/main.py new file mode 100644 index 0000000..db1b3d1 --- /dev/null +++ b/project image to pdf converter/main.py @@ -0,0 +1,15 @@ +from PIL import Image + +def img2pdf(img_path, pdf_path): + images = [] + + for file in img_path: + img = Image.open(file) + img = img.convert('RGB') + images.append(img) + + images[0].save(pdf_path, save_all=True, append_images=images[1:]) + + print('Done') + +# img2pdf(['1.jpg', '2.jpg', '3.jpg'], 'test.pdf') diff --git a/project image to pdf converter/requirements.txt b/project image to pdf converter/requirements.txt new file mode 100644 index 0000000..1e8732e --- /dev/null +++ b/project image to pdf converter/requirements.txt @@ -0,0 +1 @@ +Pillow==9.2.0 \ No newline at end of file diff --git a/project_age_calculate/calculate.py b/project_age_calculate/calculate.py new file mode 100644 index 0000000..ea29886 --- /dev/null +++ b/project_age_calculate/calculate.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +import time +from calendar import isleap + +# judge the leap year +def judge_leap_year(year): + if isleap(year): + return True + else: + return False + + +# returns the number of days in each month +def month_days(month, leap_year): + if month in [1, 3, 5, 7, 8, 10, 12]: + return 31 + elif month in [4, 6, 9, 11]: + return 30 + elif month == 2 and leap_year: + return 29 + elif month == 2 and (not leap_year): + return 28 + + +name = input("input your name: ") +age = input("input your age: ") +localtime = time.localtime(time.time()) + +year = int(age) +month = year * 12 + localtime.tm_mon +day = 0 + +begin_year = int(localtime.tm_year) - year +end_year = begin_year + year + +# calculate the days +for y in range(begin_year, end_year): + if (judge_leap_year(y)): + day = day + 366 + else: + day = day + 365 + +leap_year = judge_leap_year(localtime.tm_year) +for m in range(1, localtime.tm_mon): + day = day + month_days(m, leap_year) + +day = day + localtime.tm_mday +print("%s's age is %d years or " % (name, year), end="") +print("%d months or %d days" % (month, day)) \ No newline at end of file diff --git a/pronic_number/pronic_number.py b/pronic_number/pronic_number.py new file mode 100644 index 0000000..0d48ab1 --- /dev/null +++ b/pronic_number/pronic_number.py @@ -0,0 +1,17 @@ +#isPronicNumber() will determine whether a given number is a pronic number or not +def isPronicNumber(num): + flag = False; + + for j in range(1, num+1): + #Checks for pronic number by multiplying consecutive numbers + if((j*(j+1)) == num): + flag = True; + break; + return flag; + +#Displays pronic numbers between 1 and 100 +print("Pronic numbers between 1 and 100: "); +for i in range(1, 101): + if(isPronicNumber(i)): + print(i), + print(" "), \ No newline at end of file diff --git a/reverse_number/reverse_number.py b/reverse_number/reverse_number.py new file mode 100644 index 0000000..21b719a --- /dev/null +++ b/reverse_number/reverse_number.py @@ -0,0 +1,10 @@ +print("Enter a Number: ") +num = int(input()) + +rev = 0 +while num!=0: + rem = num%10 + rev = rem + (rev*10) + num = int(num/10) + +print("\nReverse =", rev) \ No newline at end of file