![luiscortes011001](/avatars/27639.jpg)
luiscortes011001
02.07.2020 •
Computers and Technology
What is the output of the code below assuming that global variable x has value 2 and global y has value 3? def f1(): return "ab" def f2(): return f1() * x def f3(): return f2() + f1() * y print(f3())
Solved
Show answers
More tips
- F Food and Cooking How to Make Lazy Cabbage Rolls? Simple Steps to a Delicious Dish...
- F Food and Cooking Unusually Delicious Shashlik - Follow the Etiquette of Proper Preparation!...
- L Leisure and Entertainment Couchsurfing: A New Way to Travel...
- G Goods and services Which TV is better - LCD or Plasma?...
- S Sport How to Learn to Pull Up on Monkey Bars?...
- L Leisure and Entertainment Scrapbooking: What is it and Why is it Becoming More Popular?...
- C Computers and Internet Where did torrents.ru move to?...
- B Business and Finance Understanding Cash Flow: What It Is and How It Works...
- C Computers and Internet What Are Peers and Seeds in Torrenting?...
- H Health and Medicine 10 Simple Techniques on How to Boost Your Mood...
Answers on questions: Computers and Technology
- C Computers and Technology •what command-line utility can you use to assign the correct dns server ip address...
- C Computers and Technology In computer architecture, what is the memory segment used by processes to communicate instructions and data to each other?...
- C Computers and Technology Review Questions 1. Explain the difference between authentication and authorization....
- M Mathematics Mrs. Bryant is making 17 Christmas ornaments. It takes 30 minutes to make each ornament. If she begins at 1430, at what time will she finish? (Write in military time)...
- H Health Que es una contracción muscular...
- C Chemistry A student experimentally determines the density of a plastic cube using the caliper method, liquid displacement method, and suspension method. The cube s true density...
- L Law Think about the positive and negative impacts of government on individuals in society. Why is government necessary in the United States? Use the Essay Draft Organizer...
- P Physics Five charges are placed in a closed box. Each charge (except the first) has a magnitude which is twice that of the previous one placed in the box. All charges have...
- E English From Beowulf Translated by Burton Rafel WORD LIST Tail stalked gorge gruesome withing loathsome A DIRECTIONS: In each of the following items, think about the meaning...
- M Mathematics A Math Give up Show Example Record: 1/5 Score: 1 Penaltys: 1 oft Complete: % Grade: 0% Joseph Ramos Rotation of a Point Sep 14, 8:10 05 AM ? What is the image of the...
Ответ:
Following are the output to the given method:
Program Explanation:
Defining a global variable "x,y" that holds an integer value that are "2,3".Declaring three method, "f1, f2, and f3".In the "f1" method is declared that returns a string value that is "ab".In the "f2" method it calls the f1 method that multiply the value with x, which it prints f1 method value 2 times.In the "f3" method it calls the f2 method with f1 that multiply the value with y, that adds and prints f2 and f1 method that prints 5 times.Program:
#declaring the global variable
x=2#defining x variable that hold integer value
y=3#defining y variable that hold integer value
def f1():#defining a method f1
return "ab"#using return keyword that return string value
def f2():#defining a method f2
return f1() * x#using return keyword that call f1 method
def f3():#defining a method f3
return f2() + f1() * y#using return keyword that calls f2 method and call f1 method and multiple value by 3
print(f3())#calling method f3
Output:
Please find the attached file.
Learn more:
link
Ответ:
ababababab
Explanation:
The code above is written in python and python uses indentation .So let me rephrase the code accordingly and explain what the code really do.
Note x and y is a global variable which can be used by any of the function declared. According to the question x and y are 2 and 3 respectively
The first block of code describes a function f1 without any argument but the code should return the string "ab"
def f1():
return "ab"
The second block of code defines a function f2 and returns the value of f1 multiply by x. This means you are multiplying the string "ab" by 2 which will be equals to abab
def f2():
return f1() * x
The third block of code declared a function f3 and returns the sum of f2 and product of f1 and y. using PEMDAS principle the multiplication aspect will be solved first so, ab × 3 = ababab, then we add it to f2 . ababab + abab = ababababab.
def f3():
return f2() + f1() * y
Finally, we print the function f3 value to get ababababab
print(f3())
If you run the code on your IDE like below you will get ababababab
x = 2
y = 3
def f1():
return "ab"
def f2():
return f1() * x
def f3():
return f2() + f1() * y
print(f3())
Ответ: