Question

In: Computer Science

Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the...

Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the user for three numbers and use the lambda function to print the sum [6 marks]

Question5:

Write a generator function which generates the Fibonacci series. [0,1,2,4,8,16,…]. The Fibonacci series is a list of numbers where each number is the sum of the previous two. [3 marks]
Then write the code to iterate through the first six numbers of sequence. [3 marks]
Question6: Write a program to read the file 202010mid.txt, store the content in a list of tuples, then print the list. [6 marks]

Question7: Write Python code to do the following operations using request library. [12 marks]

Check if the following webpage is available or not: https://edition.cnn.com/news.html [4 marks]
Send a get request to the following webpage and show the result: http://api.open-notify.org/iss-pass.json [4 marks]
The webpage from part 2 is expecting some parameters as shown from the results. Now create a parameter with two key:value pairs as per the following: lat with value 40.71 and lon with value -74. Send a get request now with the parameter you created and display the result.[4 marks]

Solutions

Expert Solution

# Q.4 performing a addition of three number 
print("Please enetr three numbers")
a=int(input())
b=int(input())
c=int(input())
summ = (lambda x, y, z: (x + y) + z)(a, b, c) 
print("sum is:",summ) 

#Q.5 Python program to print first n Fibonacci numbers 

def printFibonacciNumbers(n): 
        
        f1 = 0
        f2 = 1
        if (n < 1): 
                return
        for x in range(0, n): 
                print(f2, end = " ") 
                next = f1 + f2 
                f1 = f2 
                f2 = next
print("\nFirst 6 numbes of Fibonacci series are: ")             
printFibonacciNumbers(6) 

I hope it helps.


Related Solutions

Create a bash script that takes numbers as parameters, calculates sum and prints the result. If...
Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result.
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result. Submit your program as LastName_FirstName.sh file.
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
Write a program in C++ that calculates the sum of two fractions. The program should ask...
Write a program in C++ that calculates the sum of two fractions. The program should ask for the numerators and denominators of two fractions and then output the sum of the two fractions. You will need to write four functions for this program, one to read the inputted data, one to calculate the sum of the two fractions, one to find the Greatest Common Divider (GCD) between the numerator and denominator and a function that will display the end result....
Use C++ language Create a program which will ask the user to input three songs for...
Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for...
Make a function that calculates the summation of even numbers in the range. The function sum...
Make a function that calculates the summation of even numbers in the range. The function sum takes the two integer parameters and they are used as the range. The function uses default parameters for the range. When we call this function with one argument, it will be used as a starting point and the end of the range will be 100. Also, the function is called without any argument, the default range (0,100) will be used. We will use default...
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal",...
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal", "python", "break", "two", "ruby"] by: a) the last 2 characters of each list item in reverse order b) create new list from list above where each item has only 3 characters and first one is capitalized. For example, the list item = "democratic" will transform into "Dem". Apply alphabetically sorting to the new list.  
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
1. A) How many three-digit numbers are there for which the sum of the digits is...
1. A) How many three-digit numbers are there for which the sum of the digits is at least 25? B) How many three-digit numbers can be formed if only odd numbers are allowed to be re-used Please combinatorics principles where applicable.
Use calculus to find three positive numbers that sum to 150 with the greatest possible product.
Use calculus to find three positive numbers that sum to 150 with the greatest possible product.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT