accenture-new-coding
accenture-new-coding
Input Format
First line of the input is an integer y, the side of the square hall.
Second line of the input is an integer x, the side of the square table placed for
display.
Output Format
Output should display the area of the floor that is to be decorated with the
carpet.
Refer sample input and output for formatting specifications.
Sample Input 1
7
3
Sample Output 1
40
Sample Input 2
5
2
Sample Output 2
21
Solution
sh = int(input())
st = int(input())
print(sh**2-st**2)
Testcase: 1
Input
5
2
Output
21
*********************************************************************
WonderWorks Magic Show
The Magic Castle, the home of the Academy of Magical Arts at California has
organized the great ‘WonderWorks Magic Show’. 3 renowned magicians were invited to
mystify and thrill the crowd with their world’s spectacular magic tricks. At the
end of each of the 3 magicians’ shows, the audience were requested to give their
feedback in a scale of 1 to 10. Number of people who watched each show and the
average feedback rating of each show is known. Write a program to find the average
feedback rating of the WonderWorks Magic show.
Input Format
First line of the input is an integer value that corresponds to the number of
people who watched show 1.
Second line of the input is a float value that corresponds to the average rating of
show 1.
Third line of the input is an integer value that corresponds to the number of
people who watched show 2.
Fourth line of the input is a float value that corresponds to the average rating of
show 2.
Fifth line of the input is an integer value that corresponds to the number of
people who watched show 3.
Sixth line of the input is a float value that corresponds to the average rating of
show 3.
Constraints
0<=Average rating <=10
Sample Input 1
400
9.8
500
9.6
100
5
Sample Output 1
9.22
Solution
show = [0]*3
rat = [0]*3
for i in range(0,3):
show[i] = int(input())
rat[i] = float(input())
rat[i] = show[i]*rat[i]
print(round((sum(rat)/sum(show)),2))
Testcase:
Input
4000
9
500
9
100
9
Output
9.0
******************************************************************
********************************************************************
3)def are_anagrams(str1, str2):
# Remove spaces and convert both strings to lowercase
str1 = str1.replace(" ", "").lower()
str2 = str2.replace(" ", "").lower()
# Example usage:
string1 = "listen"
string2 = "silent"
result = are_anagrams(string1, string2)
print(result)
*********************************************************************
4)def swap_characters(str, ch1, ch2):
# Replace ch1 with a temporary unique character
temp_char = '###'
str = str.replace(ch1, temp_char)
# Replace ch2 with ch1
str = str.replace(ch2, ch1)
# Replace the temporary character with ch2
str = str.replace(temp_char, ch2)
return str
output:
Heool wlrod
*******************************************************************
5)def reverse_string_word_wise(input_str):
# Split the input string into words
words = input_str.split()
# Reverse the order of words
reversed_words = words[::-1]
# Join the reversed words to form the final string
reversed_str = ' '.join(reversed_words)
return reversed_str
# Example usage:
input_str = "Hello, world!"
result = reverse_string_word_wise(input_str)
print(result)
# Output: "world! Hello,"
*******************************************************************
6)def is_palindrome(input_str):
# Remove spaces and convert the string to lowercase
input_str = input_str.replace(" ", "").lower()
# Example usage:
string1 = "racecar"
string2 = "hello"
result1 = is_palindrome(string1)
result2 = is_palindrome(string2)
print(result1) # Output: 1 (True)
print(result2)
*******************************************************************
import re
# Check if the password contains at least one uppercase letter, one lowercase
letter, and one digit
if not re.search(r'[A-Z]', password) or not re.search(r'[a-z]', password) or
not re.search(r'\d', password):
return False
return True
# Example usage:
password = "Password123" # Example password
if check_password(password, 8):
print("Password is valid!")
else:
print("Password is invalid.")
*****************************************************************
Arrays:
def find_intersection(arr1, arr2):
set1 = set(arr1)
set2 = set(arr2)
intersection = set1.intersection(set2)
return list(intersection)
# Example usage:
arr1 = [1, 2, 3, 4, 5]
arr2 = [3, 4, 5, 6, 7]
result = find_intersection(arr1, arr2)
print(result)
# Output: [3, 4, 5]
*********************************************************************
def merge_sorted_arrays(arr1, arr2):
merged_array = []
i, j = 0, 0
return merged_array
# Example usage:
arr1 = [1, 3, 5, 7]
arr2 = [2, 4, 6, 8]
result = merge_sorted_arrays(arr1, arr2)
print(result)
# Output: [1, 2, 3, 4, 5, 6, 7, 8]
**********************************************************************
def remove_duplicates(nums):
if not nums:
return 0 # Return 0 for an empty array
return unique_count
# Example usage:
nums = [1, 1, 2, 2, 2, 3, 4, 4, 5]
new_length = remove_duplicates(nums)
print(nums[:new_length]) # Output: [1, 2, 3, 4, 5]
*******************************************************************
def reverse_array(nums, start, end):
while start < end:
nums[start], nums[end] = nums[end], nums[start]
start += 1
end -= 1
# Example usage:
nums = [1, 2, 3, 4, 5, 6, 7]
k = 3 # Rotate by 3 steps
rotate_array(nums, k)
print(nums)
# Output: [5, 6, 7, 1, 2, 3, 4]
************************************************************************
def max_subarray_sum(arr):
max_ending_here = max_so_far = arr[0]
return max_so_far
# Example usage:
arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
result = max_subarray_sum(arr)
print(result)
# Output: 6 (The largest sum is from [4, -1, 2, 1])
************************************************************************