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
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 " )
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 )
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: ...
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 " )
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...
# 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 = ...