0% found this document useful (0 votes)
9 views3 pages

Def Main

Uploaded by

shahir.kadiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Def Main

Uploaded by

shahir.kadiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

6.

def hamming_distance(str1, str2):


if len(str1) != len(str2):
return "Error: Strings are not of the same length."

distance = 0
for char1, char2 in zip(str1, str2):
if char1 != char2:
distance += 1
return distance

# Prompting the user to enter two strings


string1 = input()
string2 = input()

# Calculating the Hamming distance


result = hamming_distance(string1, string2)

# Printing the result


print(result)

-----------------------
10.def is_same_parity(val1, val2):
return (val1 % 2) == (val2 % 2)

def main():
# Read input values
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = int(input())

queries = []
for _ in range(q):
r1, c1 = map(int, input().split())
r2, c2 = map(int, input().split())
queries.append(((r1-1, c1-1), (r2-1, c2-1))) # Adjust for 0-based index

results = []

for (r1, c1), (r2, c2) in queries:


value_A = a[r1] + b[c1]
value_B = a[r2] + b[c2]
if is_same_parity(value_A, value_B):
results.append("YES")
else:
results.append("NO")

# Print results for all queries


for result in results:
print(result)

if __name__ == "__main__":
main()
--------------
55.def fizz_buzz(number):
if number % 3 == 0 and number % 5 == 0:
return "FizzBuzz"
elif number % 3 == 0:
return "Fizz"
elif number % 5 == 0:
return "Buzz"
else:
return str(number)

# Prompting the user to enter a number


number = int(input())

# Getting the result from the fizz_buzz function


result = fizz_buzz(number)

# Printing the result


print(result)

----------------------------------------------
34.def multiply_strings(A, B):
# Edge case: if either number is zero
if A == "0" or B == "0":
return "0"

# Convert the input strings to integers


num1 = int(A)
num2 = int(B)

# Multiply the integers


product = num1 * num2

# Convert the result back to a string and return


return str(product)

# Sample Input
A = input()
B = input()

# Function Call and Output


print(multiply_strings(A, B))

--------
19.def find_first_repeating(arr):
# Dictionary to store the first occurrence index of each element
index_map = {}
# Variable to store the minimum index of the first repeating element
min_index = float('inf')
# Variable to store the first repeating element
first_repeating = -1

# Traverse the array


for i, num in enumerate(arr):
if num in index_map:
# If the element is already in index_map, it means it's repeating
if index_map[num] < min_index:
min_index = index_map[num]
first_repeating = num
else:
# Store the index of the first occurrence of the element
index_map[num] = i

# Return the first repeating element


return first_repeating if first_repeating != -1 else "No repeating elements"

# Function to take input from the user


def get_input():
# Take input from the user
user_input = input()
# Convert the input string into a list of integers
arr = list(map(int, user_input.split()))
return arr

# Main part of the program


def main():
arr = get_input()
result = find_first_repeating(arr)
print(f"{result}")

# Run the main function


if __name__ == "__main__":
main()

You might also like