Posts

Showing posts from June, 2023

12th_replace_first_letter_in_capital

  mystring = " learn python " print ( mystring . title ())

11th_remove_word_from_string

  text = input ( " Enter the string: " ) word = input ( " Enter a word to delete: " ) text = text . replace ( word , "" ) print ( text )

10th_comma_separator

  str = input ( " Enter a string: " ) print ( list ( str )) #print(tuple(str)) #print(set(str))

9th_remove_duplicates_from_list

  def remove_duplicates ( lst ):     return list ( set ( lst )) my_list = [ 1 , 2 , 4 , 2 , 1 , 4 , 5 ] print ( " Original list: " , my_list ) new_list = remove_duplicates ( my_list ) print ( " list after removing duplicate elements: " , new_list )

8th_has_duplicate_check_function

  def has_duplicates ( v ): #Called function     c = 0     for i in range ( len ( v )):         for j in range ( i + 1 , len ( v )):             if v [ i ]== v [ j ]:                 c = c + 1     if c > 0 :         print ( True )     else :         print ( False ) v =[ 1 , 2 , 3 , 2 , 3 ] #main() function print ( " List is: " , v ) has_duplicates ( v ) #Calling function

7th_is_sorted_function_check_list

  def is_sorted ( stuff ):     for i in range ( len ( stuff )- 1 ):         if stuff [ i ]> stuff [ i + 1 ]:             return False     else :         return True numbers =[ 1 , 2 , 3 , 4 , 0 ] print ( is_sorted ( numbers ))

6th_palindrome

  def palindrome ( s ):     rst = ""     for i in range ( len ( s )):         rst = s [ i ]+ rst     if s == rst :         return True     else :         return False st = input ( " Enter a string: " ) r = palindrome ( st ) if r == True :     print ( " The given string is palindrome " ) else :     print ( " The given string is not palindrome " )

5th_gcd

import math print ( " The gcd of 60 and 48 is: " , end = "" ) print ( math . gcd ( 60 , 48 ))  

4th_to_print_prime_no

  n1 = int ( input ( " Enter lowest interval: " )) n2 = int ( input ( " Enter highest interval: " )) for num in range ( n1 , n2 + 1 ):     if num > 1 : #all prime numbers are greater than 1         for i in range ( 2 , num ):             if num % i == 0 :                 break         else :             print ( num )

3rd_fibonacci_series

  n = int ( input ( " Enter a number up to generate fibonacci series: " )) a = 0 b = 1 while a < n :     print ( a , end = " " )     c = a + b     a = b #the value of a is updated to be equal to the value of b     b = c #the value of b is updated to be equal to the value of c ''' teration 1:     a = 0     b = 1     Since 0 < 20, the condition is true.     Output: 0 Iteration 2:     a = 1     b = 1     Since 1 < 20, the condition is true.     Output: 1 Iteration 3:     a = 1     b = 2     Since 1 < 20, the condition is true.     Output: 1 Iteration 4:     a = 2     b = 3     Since 2 < 20, the condition is true.     Output: 2 Iteration 5:     a = 3     b = 5     Since 3 < 20, the condition is true.     Output: 3 Iteration 6:     a = 5     b = 8     Since 5 < 20, the condition is true.     Output: 5 Iteration 7:     a = 8     b = 13     Since 8 < 20, the condition is true.     Output: 8 Iteration 8:     a = 13     b = 21     Since

2nd_char_type_checker

  ch = input ( " Enter a character: " ) if ch >= ' a ' and ch <= ' z ' :     print ( " Given character is lowercase character " ) elif ch >= ' A ' and ch <= ' Z ' :     print ( " Given character is uppercase character " ) elif ch >= ' 0 ' and ch <= ' 9 ' :     print ( " Given character is digit " ) else :     print ( " Given character is special character " )

1st_pattern_program

  for i in range(5,0,-1):     for j in range(6-i):         print(i,end=" ")     print()#-->use to print in next line '''Inner Loop: for j in range(6-i): Iteration 1 (i = 6): j will not execute as range(6 - 6) results in an empty range. Iteration 2 (i = 5): j will execute once as range(6 - 5) results in range(1). Iteration 3 (i = 4): j will execute twice as range(6 - 4) results in range(2). Iteration 4 (i = 3): j will execute thrice as range(6 - 3) results in range(3). Iteration 5 (i = 2): j will execute four times as range(6 - 2) results in range(4). Iteration 6 (i = 1): j will execute five times as range(6 - 1) results in range(5). Now, let's print the output for each iteration: Iteration 1 (i = 6): No output from the inner loop as range(6 - 6) is an empty range. Iteration 2 (i = 5): Output: 5 (Printed once from the inner loop) Iteration 3 (i = 4): Output: 4 4 (Printed twice from the inner loop) Iteration 4 (i = 3): Output: 3 3 3 (Printed thrice from the i

love_calculator

  # Python Tkinter GUI based "LOVE CALCULATOR" # import tkinter from tkinter import * # import random module import random # Creating GUI window root = Tk() # Defining the container size, width=400, height=240 root.geometry('400x240') # Title of the container root.title('Love Calculator????') # Function to calculate love percentage # between the user ans partner def calculate_love():     # value will contain digits between 0-9     st = '0123456789'     # result will be in double digits     digit = 2     temp = "".join(random.sample(st, digit))     result.config(text=temp) # Heading on Top heading = Label(root, text='Love Calculator - How much is he/she into you') heading.pack() # Slot/input for the first name slot1 = Label(root, text="Enter Your Name:") slot1.pack() name1 = Entry(root, border=5) name1.pack() # Slot/input for the partner name slot2 = Label(root, text="Enter Your Partner Name:") slot2.pack() name2 =