-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterview_question.py
More file actions
93 lines (52 loc) · 2.28 KB
/
interview_question.py
File metadata and controls
93 lines (52 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#>>>>>>>>>>>>>>>>> to Check whether the num is Palindrome or not ---- without ffunction--------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# num= int(input("enter the number"))
# num_str = str(num)
# if num_str==num_str[::-1]:
# print(f"{num} is a palindrome")
# else:
# print(f"{num} is not a palindrome")
#>>>>>>>>>>>>>>>>> to Check whether the num is Palindrome or not ---- without ffunction--------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# def is_palindrome(num):
# num_str = str(num)
# return num_str==num_str[::-1]
# num = (input("enter the number or string: "))
# if is_palindrome(num):
# print(f"'{num}' is Palindrome")
# else:
# print(f"'{num}' is not Palindrome")
###### I.Q....................Program to find factorial of a number.....................................
# def factorial(n):
# if n == 0:
# return 1
# else:
# return n * factorial(n - 1)
# number = int(input("Enter a number: "))
# if number < 0:
# print("Factorial is not defined for negative numbers.")
# else:
# print(f"The factorial of {number} is {factorial(number)}.")
### 1.Program to create a class called "Restaurant"
### with attributes for menu items, prices, and ratings,
### and methods to add and remove items, and to calculate average rating.
# class Restaurent:
# def __init__(self):
# self.menu_items = {}
# self.ratings = []
# def add_items(self,items,price):
# self.menu_items[items] = price
# def remove_item(self,item):
# if item in self.menu_items:
# del self.menu_items[item]
# def add_rating(self,rating):
# self.ratings.append(rating)
# def average_rating(self):
# if sum(self.ratings) / len(self.ratings):
# return 0
# restaurent = Restaurent()
# restaurent.add_items("Juice",100)
# restaurent.add_items("Shake",50)
# restaurent.add_items("Mojito",35)
# restaurent.add_rating(10)
# restaurent.add_rating(15)
# print("Menu :",restaurent.menu_items)
# print("Average Rating : " ,restaurent.average_rating())