import numpy as np
import scipy.linalg as la
import matplotlib.pyplot as plt
3. Choose an angle θ and set the variable theta to its value (a number).
4. What is sin θ? cos θ? Angles can be measured in degrees or radians.
Which of these are being used used?
import numpy as np
import scipy.linalg as la
import matplotlib.pyplot as plt
1. Choose a value and set the variable x to that value.
2. What is command to compute the square of x? Its cube?
# Looks great! # . I would come up with a better name for d
# test if the user wants to quit...
# Is not quite right... Change this print('I thought of another number, try again')
# to something more like "Not Quite, Please try again"
from random import randint
play = input('You want to start? y/n ')
def play_game():
# Put the rules here
# While loop goes here
d = randint(7, 50)
computer_num = randint(1, d)
lives = d // 2
while lives > 0:
try:
num = int(input(f'enter number from 1 to {d}, you have {lives} attempts left '))
if num > d or num < 1:
raise ValueError
except:
print('incorrect input, try again')
continue
if num == computer_num:
print(f'you won, I thought number {computer_num}')
return None
else:
lives -= 1
if lives > 0:
print('I thought of another number, try again')
print(f'you lost, I thought number {computer_num}')
play = input('You want to start the game[y/n]: ')
while play.lower() == 'y':
play_game()
play = input('You want to play again? y/n ')Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.
input : 5
0 2
1 3
2 1
4 7
expected output : 7x^4 + 6x^3 + x^2 + 3x + 2
your output: 7x^4 + 6x^3 + 1x^2 + 3 + 2please explain this
Secret Message - 2
Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.
a b c d e f g h i j k l m n o p q r s t u v w x y z
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
Input
Input will be a string in single line containing spaces and letters both uppercase and lowercase.
Output
Output should be a single line containing secret message. All characters in output should be in lower case.
Explanation
For example, if input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So output be "16-25-20-8-15-14".
Sample Input 1
python
Sample Output 1
16-25-20-8-15-14
Sample Input 2
python learning
Sample Output 2
16-25-20-8-15-14 12-5-1-18-14-9-14-7given a sentence in camel case and want to convert to snake case using for loop and indexing
write a function that takes an array of integers as input and prints the second maximum difference between any two elements from an array in python
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
Sample Input
python4 anjali25
Sample Output
python25 anjali4
Sample Input
1python254
Sample Output
254python1
Sample Input
-1pyth-4on 5lear-3ning-2
Sample Output
5pyth4on 3lear2ning1
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.
Input
The input will be a single line containing a string.
Output
The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.
Explanation
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
Sample Input
python4 anjali25
Sample Output
python25 anjali4
Sample Input
I am 2 years and 3 months old. This sentence4 5should be 6rearr7anged8.
Sample Output
I am 8 years and 7 months old. This sentence6 5should be 4rearr3anged2.
Make a game where the computer will guess a random number for different given ranges eg 1-10, 10-20, 30-20. You are given only 5 lives double digits are allowed like 11. the program must return not a number in the given range if you input anything that isnt in the given range for example 1-10; 1,2,3,4,5,6,7,8,9,10. The program should also ask you if u want to play again