a) Write a program which allows a student to enter a string and test for whether string is a palindrome or not. If string is a palindrome replace all characters with random numbers between 1 and 100 and displays the output, else prompt student re-enter string.
b) Write a program which allows a company secretary to write employee details in file called EmployeeHours.txt and retrieves the information using pointers to display it on the screen.
# Python 3.9.5
# a)
#
# import random
#
#
# def isPalindrome(s):
# # Run loop from 0 to len/2
# for i in range(0, int(len(s) / 2)):
# if s[i] != s[len(s) - i - 1]:
# print('String is not palindrome!')
# main()
# new_str = ''
# for i in range(1, len(s)+1):
# new_str += str(random.randint(1, 101))
# if new_str is not None:
# print(new_str)
# exit()
#
#
# def main():
# s = input('Enter string: ')
# isPalindrome(s)
#
#
# if __name__ == '__main__':
# main()
# b)
text = input('Enter details: ')
with open('EmployeeHours.txt', 'w') as f:
f.write(text)
f.close()
Comments
Leave a comment