answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AysviL
2 months ago
10

Let's revisit our lucky_number function. We want to change it, so that instead of printing the message, it returns the message.

This way, the calling line can print the message, or do something else with it if needed. Fill in the blanks to complete the code to make it work.
def lucky_number(name):
number = len(name) * 9
___ = "Hello " + name + ". Your lucky number is " + str(number)
___

print(lucky_number("Kay"))
print(lucky_number("Cameron"))
Computers and Technology
1 answer:
oksian1 [950]2 months ago
3 0

Answer:

Fill in the first blank with:

message = "Hello " + name + ". Your lucky number is " + str(number)

Fill in the second blank with:

return message

Explanation:

The first blank must be completed with a variable, and any variable name can be chosen as long as it adheres to naming conventions.

For this instance, I have chosen the variable name "message", without including quotes.

For the next blank, it should return the variable defined in the line above;

Thus, the appropriate completion for this blank will be "return message", without the quotes.

You might be interested in
Which of the following statements are true about the growth of technology? Select 3 options. A. Individuals in the United States
oksian1 [950]
The answer is b. Explanation: The general population started accessing the internet following the advent of the World Wide Web.
4 0
21 day ago
Read 2 more answers
This program will calculate the rise in ocean levels over 5, 10, and 50 years, Part of the program has been written for you. The
maria [1035]

Answer:

Here is the C++ code:

#include <iostream> //for utilizing input and output functions

using namespace std; //for defining objects cin cout

int main(){ //beginning of the main function

     

   double risingLevel; //declares a variable of type double to store the rising level

   cin>>risingLevel; //captures the risingLevel input from the user

   

   cout<<"Level: "<<risingLevel<<endl; //outputs the rising level

   cout << "Years: 5, Rise: " << risingLevel * 5<<endl; //outputs the increase in ocean level over 5 years

   cout << "Years: 10, Rise: " << risingLevel * 10<<endl; //outputs the increase in ocean level over 10 years

   cout << "Years: 50, Rise: " << risingLevel * 50<<endl; //outputs the increase in ocean level over 50 years

}

Explanation:

The functioning of the program is as follows:

Supposing the user inputs a rising level of 2.1, then,

risingLevel = 2.1

At that point, the first print statement (cout):

cout<<"Level: "<<risingLevel<<endl; outputs the value of risingLevel to the display. Therefore, this line shows:

Level: 2.1

Next, the program proceeds to the following statement:

   cout << "Years: 5, Rise: " << risingLevel * 5<<endl;

which calculates the increase in ocean levels for a duration of 5 years using the equation:

risingLevel * 5 = 2.1 * 5 = 10.5

It subsequently shows the calculated result on the display. So, this line shows:

Years: 5, Rise: 10.5 Then, the control shifts to the next statement:

   cout << "Years: 10, Rise: " << risingLevel * 10<<endl;

that computes the rise in ocean levels over a span of 10 years using the equation:

risingLevel * 10 = 2.1 * 10 = 21

It then showcases the calculated figure on the output screen. Thus, the output is:

Years: 10, Rise: 21

Next, the program control progresses to this statement:

   cout << "Years: 50, Rise: " << risingLevel * 50<<endl;

which determines the rise in ocean levels for a duration of 50 years using the equation:

risingLevel * 50 = 2.1 * 50 = 105

This then displays the computed result on the output screen, leading to the output:

Years: 50, Rise: 105 Consequently, the complete output from the program will be:

Level: 2.1 Years: 5, Rise: 10.5

Years: 10, Rise: 21

Years: 50, Rise: 105

4 0
21 day ago
Doug grew up on a large farm in southwest Wisconsin. As a college graduation gift, Doug’s father gave him several hundred acres
zubka84 [1067]
Answer: Sole Proprietorship. This question seeks to identify the business type mentioned in the scenario. In a Sole Proprietorship, the owner effectively is the business, managing all elements from operations to finance. Typically, this is the initial business form in entrepreneurship. The description fits Doug well; he operates the farming business independently, taking care of all its functions. Thus, it qualifies as a sole proprietorship.
5 0
1 month ago
there is a structure called employee that holds information like employee code, name, date of joining. Write a program to create
oksian1 [950]

Answer:

The following is the C program:

#include<stdio.h>

#include<conio.h>

struct employee{

char empname[50]; int empcode, day, mon, yr;

} employees[30];

int main(){

int total;

printf("Numbers of Employees: "); scanf("%d",&total);

for(int kt=0; kt<total; kt++){

printf("Employee Code: "); scanf("%d",&employees[kt].empcode);

printf("Name: "); scanf("%s", employees[kt].empname);

printf("Date of Joining [dd mm yyyy]: "); scanf("%d%d%d",&employees[kt].day,&employees[kt].mon,&employees[kt].yr); }

int year;

printf("\nCurrent Date [Year only]: "); scanf("%d", &year);

printf("Code\t\t\t Name\t\t\t Date of Joining\n");

for(int kt=0; kt<total; kt++)

if((year - employees[kt].yr) >= 15)

printf("%d\t\t\t %s\t\t\t %d/%d/%d\n", employees[kt].empcode, employees[kt].empname, employees[kt].day, employees[kt].mon, employees[kt].yr);

}

Explanation:

Refer to the attached document for clarification, including comments that elucidate certain lines

Download txt
3 0
21 day ago
The factorial of a nonnegative integer n is written n ! (pronounced "n factorial") and is defined as follows: n ! = n · (n - 1)
Harlamova29_29 [1022]
Here are the programs. I have written C++ and Python scripts:

a)

C++

#include<iostream>  

using namespace std;  

int factorial(int num)  {  

   if (num == 0)  

       return 1;  

   return num * factorial(num - 1);  }    

int main()  {  

   int integer;

   cout<<"Enter a non negative integer: ";

   cin>>integer;

   cout<< "Factorial of "<< integer<<" is "<< factorial(integer)<< endl;  }

Python:

def factorial(num):  

   if num == 0:  

       return 1

   return num * factorial(num-1)  

integer = int(input("Enter a non negative integer: "))  

print("Factorial of", integer, "is", factorial(integer))

b)

C++

#include <iostream>  

using namespace std;

double factorial(int number) {  

if (number == 0)  

 return 1;  

return number * factorial(number - 1); }  

 

double estimate_e(int num){

    double e = 1;

    for(int i = 1; i < num; i++)

     e = e + 1/factorial(i);

     cout<<"e: "<< e; }  

 

int main(){

int term;

cout<<"Enter a term to evaluate: ";

cin>>term;

estimate_e(term);}

Python:

def factorial(number):  

   if number == 0:  

       return 1

   return number * factorial(number-1)  

def estimate_e(term):

   if not term:

       return 0

   else:

       return (1 / factorial(term-1)) + estimate_e(term-1)

number = int(input("Enter how many terms to evaluate "))

print("e: ", estimate_e(number))

c)

C++

#include <iostream>

using namespace std;

int main(){

   float terms, sumSeries, series;

   int i, number;

   cout << " Input the value of x: ";

   cin >> number;

   cout << " Input number of terms: ";

   cin >> terms;

   sumSeries = 1;

   series = 1;

   for (i = 1; i < terms; i++)      {

       series = series * number / (float)i;

       sumSeries = sumSeries + series;     }

   cout << " The sum  is: " << sumSeries << endl;  }  

Python    

def ePowerx(number,terms):

   sumSeries = 1

   series =1

   for x in range(1,terms):

       series = series * number / x;

       sumSeries = sumSeries + series;

   return sumSeries    

num = int(input("Enter a number: "))

term=int(input("Enter a number: "))

print("e^x: ",ePowerx(num,term))

Explanation:

a)

The program includes a factorial method that takes a number as an argument and calculates its factorial using recursion. For instance, if number = 3

The base case occurs at  if (number == 0)

and the recursion is handled with return number * factorial(number - 1);  

With number = 3 not equaling zero, the function calls itself recursively to get the factorial of 3

return 3* factorial(3- 1);

3 * factorial(2)

3* [2* factorial(2- 1) ]

3 * 2* [ factorial(1)]

3 * 2 * [1* factorial(1- 1) ]

3 * 2 * 1* [factorial(0)]

At this point at factorial(0), the base condition is satisfied as number==0, so factorial(0) returns 1

The resulting output is:

3 * 2 * 1* 1

yielding 6

So, the final program output will be

Factorial of 3 is 6

b)

The estimate_e method takes a number, termed as num, which signifies the term to estimate the mathematical constant e

The for loop extends through each term. For example, if num is set to 3

Then the core statement:

e = e + 1/factorial(i);  

The preceding calculation works as:

e = 1 + 1/1! +1/2!

Since the term count is 3

Initially, e is set to 1

i is initialized at 1

Inserting this into the calculation gives us:

e = 1 + 1/factorial(1)

The factorial function computes and returns 1, as the factorial of 1 is 1. Thus,

e = 1 + 1/1

This results in e = 2

Proceeding to the next iteration, where i = 2 and e = 2, we calculate e = 2 + 1/factorial(2)

Thus, e = 2 + 1/2 results in e = 2.5

Following to the next iteration with i = 3, we have e = 3 + 1/factorial(3)

This yields e = 3 + 1/6 resulting in approximately e = 3.16666

Therefore, the output is:

e: 3.16666

c)

This program calculates the sum of a series based on the formula:

e^x = 1 + x/1! + x^2/2! + x^3/3! +...

The for loop iterates according to the number set for terms. Assuming x is 2, and the number of terms is set to 3, the series would read:

e^2 = 1 + 2/1! + 2^2/2!

In this setup: number = 2 and terms = 3

Initial values for series and sumSeries are both 1

Starting with i equal to 1, the update statement series = series * number / (float)i; applies as follows:series = 1 * 2 /1 results in series = 2

Then, for sumSeries, we have sumSeries = sumSeries + series; Outputs sumSeries as 1 + 2, yielding 3

Continuing to the next iteration: i=2, with series = 2 and sumSeries = 3, we recalculate as series = 2 * 2/2 imposing series = 2 again. Thus, we find: sumSeries = 3 + 2 giving a final sumSeries value of 5

After the loop concludes, the result shows the value of sumSeries, leading finally to the output value of 5
8 0
1 month ago
Other questions:
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    13·2 answers
  • Write a function solution that returns an arbitrary integer which is greater than n.
    13·1 answer
  • Write a class named Taxicab that has three **private** data members: one that holds the current x-coordinate, one that holds the
    9·1 answer
  • An array subscript can be an expression, but only as long as the expression evaluates to what type?
    7·1 answer
  • 7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho
    11·1 answer
  • Which of the following is opened when the Find command is clicked?
    12·1 answer
  • This question refers to a standard deck of playing cards. If you are unfamiliar with playing cards, there is an explanation in P
    10·2 answers
  • Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand.
    9·1 answer
  • hard disk drive has 16 platters, 8192 cylinders, and 256 4KB sectors per track. The storage capacity of this disk drive is at mo
    13·1 answer
  • Haley is helping to choose members for a customer satisfaction team. Which of the following employees demonstrate skill in focus
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!