It is the final of the world’s most prestigious cricket tournament, the Indian Premier League. In the final, the Chennai Super Kings (CSK) are playing against the Mumbai Indians (MI). There is one over left for the match to end and CSK require R runs to win with W wickets remaining.
An over consists of 6 balls. Each ball can result in any one of the following possibilities:-
If a ball results in a wicket, CSK’s remaining wickets will decrease by one. If a ball results in runs (either 6, 4, 7, 2 or 1), these runs are added to the runs that CSK have already scored.
The match ends when one of the following happens:-
* If CSK scores R runs, the match ends and CSK wins.
* If the match ends with CSK scoring exactly one run less than the required runs, then the match is a tie.
1. Give the output:
a=3
a=a+1
if a>5:
print(a)
else:
print(a+5)
Part 2
Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source.
Provide the Python code and output for your program and all your examples.
Part 1
Write a Python program that does the following.
Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.
Finally, create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references.
Create your own unique examples for this assignment. Do not copy them from the textbook or any other source.
Rearrange Numbers in String
Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.
The input will be a single line containing a string.
The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.
For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".
Sample Input
I am 5 years and 11 months old
Sample Output
I am 11 years and 5 months old
Task 1
Create a class named Ticket that represents the ticket to access a museum. The class has a constructor that takes in input a number representing the base value of the ticket. Moreover, the class has a method named "calcTicketCost(int)". The total cost of the ticket depends on the base ticket value and the number of visitors (normally, number of visitors x base value).
Create a class StudentTicket that inherits from the class Ticket and re-implement the method calcTicketCost(int) by shaping a different logic to the class such as: a discount of 40% is applied to the total ticket price.
Task 2
Create an abstract class named Ticket that represents the ticket to access a museum. The class has a constructor that takes in input a number representing the base value of the ticket
Moreover, the class has an abstract method named "calcTicketCost(int)".
In addition, create two classes, respectively named
NormalTicket and Student Ticket that inherit from the class Ticket and implement the missing abstract method calcTicketCost(int). The total cost of the ticket depends on the base ticket value and the number of visitors (normally, number of visitors x base value).
For the normal ticket the following discounts are applied: 1 to 3 visitors, no discount 4 to 7 visitors, 10% 8 to 10 visitors, 15% .More than 10, 20%
For the student ticket there is a flat discount of 40% regardless of the number of visitors.
Part 1
Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a.
while True:
y = (x + a/x) / 2.0
if y == x:
break
x = y
Part 2
Write a function named test_sqrt that prints a table like the following using a while loop, where "diff" is the absolute value of the difference between my_sqrt(a) and math.sqrt(a).
One day someone tells Pierre that there is a sweet shop across the street named
"Olivier and Bhalla's Store for Something Sweet". This was very frustrating. Pierre
contacted the authorities about the knockoff right away. The government ruled that if
the name of a knockoff brand has more than 3 different letters than the original
companies name, they are considered a novelty and are allowed to continue operating.
If the name of the knockoff company is within 3 (inclusive) letters of the original
companies name, then they are labelled as a knock off and should be closed down.
Create a function that takes two different company names, and returns wether or not
the imposter company is a Novelty, or a Knockoff.
my function dosent work pls help me with an example wat the final function looks like: