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
Degger [83]
3 years ago
9

including how it can be stored and what types of operations we can perform. For example, we can write a program that squares num

bers, but it wouldn’t be able to square a word.
Computers and Technology
1 answer:
ASHA 777 [7]3 years ago
6 0

Answer:

The solution code is written in Python:

  1. def square(num):
  2.    if type(num).__name__ == 'int':
  3.        sq_num = num * num
  4.        return sq_num  
  5.    else:
  6.        return "Invalid input"
  7. print(square(5))
  8. print(square("Test"))

Explanation:

To ensure only certain type of operation can be applied on a input value, we can check the data type of the input value. For example, we define a function and name it as <em>square</em> which take one input number, <em>num </em>(Line 1).

Before the <em>num</em> can be squared, it goes through a validation mechanism in by setting an if condition (Line 2) to check if the data type of the input number is an integer,<em> int.</em> If so, the<em> num </em>will only be squared otherwise it return an error message (Line 6).

We can test our function by passing value of 5 and "Test" string. We will get program output:

25

Invalid input

You might be interested in
What is client server relationship is the basic form of what
stepan [7]

computer network is the answer                          

8 0
3 years ago
What will you see on the next line? &gt;&gt;&gt; int(6.5)
tankabanditka [31]

Answer:

6

Explanation:

The int functions founds down to the nearest whole number, which in this case would be 6.

8 0
3 years ago
Read 2 more answers
CC stand for.....in the email platform?
Elena L [17]
CC stands for Carbon Copy in emails.
6 0
3 years ago
Read 2 more answers
Which of the following is a message sent from one person to another using the Internet?
Alexxx [7]
Where is the message lol ?
8 0
3 years ago
Read 2 more answers
Leah deals with several file conversions every day.
Lelechka [254]
That’s not a question but good for her
5 0
3 years ago
Other questions:
  • What is life all about?
    15·2 answers
  • How i can connect to internet automatically when i switch on my computer?
    8·1 answer
  • What does rwd stand for?
    8·2 answers
  • Show a single view of an object, but show it in a way that makes it look 3-D, as your eye would see it.
    10·1 answer
  • Joshua takes ownership of all his tasks. Which quality is he demonstrating?
    9·2 answers
  • Which of these BEST describes an inference?
    11·2 answers
  • Which one of these tasks is part of the pre-production phase of game development?
    11·2 answers
  • When you're working on an image, it's a good idea to make a ____________ of the image, so that you'll have the original image in
    12·2 answers
  • Google Glass, glasses that allow you to take pictures and search online by speaking commands, are introduced at a technology tra
    8·1 answer
  • Microsoft recommends when that you create passwords with upper and lowercase letters, numbers, symbols, and use at least _______
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!