1answer.
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
Aloiza [94]
3 years ago
8

If an app asks for a user's age, it may be because the app requires a user to be over a certain age to use some of the services

it provides. Write a function called checkAge that takes one parameter of type String. The function should try to convert this parameter into an Int value and then check if the user is over 18 years old. If he/she is old enough, print "Welcome!", otherwise print "Sorry, but you aren't old enough to use our app." If the String parameter cannot be converted into an Int value, print "Sorry, something went wrong. Can you please re-enter your age?" Call the function and pass in userInputAge below as the single parameter. Then call the function and pass in a string that can be converted to an integer.
Go back and update your function to return the age as an integer. Will your function always return a value? Make sure your return type accurately reflects this. Call the function and print the return value.
func checkage(age: String)->Int?
{
if let age_type = Int(age)
{
if age_type > 18 {
return "Welcome!"
}
else if age_type < 18 {
return"Sorry, but you aren't old enough to use our app."
}
}
else {
return "Sorry, something went wrong. Can you please re-enter your age?"
}
return age_type
}
Computers and Technology
2 answers:
lbvjy [14]3 years ago
7 0

Answer:

def checkage(age: "String")->int:

   if age >= 18:

       return "Welcome!"

   return "Sorry, but you aren't old enough to use our app."

   

for _ in iter(list,0):

   myage = int(input("Please enter your age: "))

   if myage is int(myage):

       result = checkage(myage)

       print(result)

       break

   print("Sorry, something went wrong. Enter integer value as age.")

   

Explanation:

The python code above lets the user input the age value for continuous comparison. If the age is an integer, it checks to know if the age is greater than 18 or not. If yes, it returns "Welcome!" else "Sorry, but you aren't old enough to use our app". But if the age is not an integer, it displays the message "Sorry, something went wrong. Can you please re-enter your age?" then prompts the user again for the age.

Note: the ': "String" ' and "->int" is for documentation purposes. They are used to describe the type of parameters (for later) and return value (the former).

Oliga [24]3 years ago
4 0

Answer and Explanation:

Here the programming language swift is being used. There is a slight error in the program shown above:

var userInputAge=9

func checkage(age: String)->int?

{

if let age_type = Int(age)

{

if age_type > 18 {

return "Welcome!"

}

else if age_type < 18 {

return"Sorry, but you aren't old enough to use our app."

}

}

else {

return "Sorry, something went wrong. Can you please re-enter your age?"

}

return age_type

}

The program should be revised :

func checkage(age: int?)->String

{

if let age_type = Int(age)

{

if age_type > 18 {

return "Welcome!"

}

else if age_type < 18 {

return"Sorry, but you aren't old enough to use our app."

}

}

else {

return "Sorry, something went wrong. Can you please re-enter your age?"

}

return age_type

}

We call the functions :

checkage(userInputAge)

checkage("15")

Note: we revised the program for errors in the first line of the code where the int optional parameter(int?) was supposed to be used instead of the String parameter in the function. We then called the function using the userInputAge variable defined as the parameter and then we now also used a String as the parameter for calling the function the second time.

You might be interested in
Please
levacccp [35]

Answer:

inspect

Explanation:

7 0
3 years ago
Question 1(Multiple Choice Worth 5 points)
aleksley [76]

Answer:

b

Explanation:

it's not a c or d and now I have to make it 20 characters long so I will do this

3 0
3 years ago
Read 2 more answers
Pros and cons of toyota's organizational structure?
GarryVolchara [31]
In 2013, Toyota changed its organizational structure from the centralized structure to: 
- the Global hierarchy, 
- the Geographic divisions, and 
- the Product-based divisions. 

This change was made to adapt the consumer's demand in each of the regional markets all over the world. The most important element of this structure is the speed of handling issues and problems of all Toyota's branches. However, this structure also has a weakness which is the decreasing of headquarter's control over the global organization.
4 0
4 years ago
HELP PLEASE
GREYUIT [131]

Answer:

D, storyboard

Explanation:

5 0
3 years ago
Part B
frosja888 [35]
Computer programming 2254518752669
8 0
3 years ago
Other questions:
  • What does microsoft recommend for large organizations requiring desktop virtualization for many clients? quizlewt?
    10·1 answer
  • Which type of spreadsheet cell represents the left hand sides (lhs) formulas in an optimization analysis?
    5·1 answer
  • is either the number of bits used to indicate the color of a single pixel, or the number of bits used for each color component o
    7·1 answer
  • Ergonomia este știința care studiază ....
    6·1 answer
  • Boardman College maintains two files—one for Sociology majors and another for Anthropology majors. Each file contains students'
    5·1 answer
  • If a system responds to a change in input by moving further away from its equilibrium condition, what type of feedback has occur
    13·1 answer
  • What is the best way to show a complex data chart in word?
    6·1 answer
  • I will give brainiest to the person that is right. What is change management?
    9·1 answer
  • State differences between title bar and menu bar​
    5·1 answer
  • How do I get the pictures from my old Samsung phone to put on my iPhone? The Samsung is turned off. Is there a way to transfer i
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!