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
Keith_Richards [23]
3 years ago
7

Create a Python program by defining a function that calculates the year of birth of a person whose age is known to you.(You may

use an input statement to ask the user to enter their age).
Computers and Technology
1 answer:
Alchen [17]3 years ago
3 0

Answer:

  1. import datetime
  2. def get_year_of_birth():
  3.    age = int(input("Enter your age: "))  
  4.    current_year = datetime.datetime.now().year  
  5.    year_of_birth = current_year - age  
  6.    return year_of_birth  
  7. print(get_year_of_birth())

Explanation:

Firstly, we import datetime module as we need it to get the current year (Line 1).

Next, create a function named it as get_year_of_birth (Line 3). Prompt user to input age and assign it to a variable (Line 4). Next, we use now() method from datetime module to get the current date and time and extract the year component (Line 5).  At last, calculate the year of birth by subtracting the current_year with age and return it as output (Line 6-7).

You might be interested in
Which of the following would determine how many elements are in values?
DiKsa [7]
I guess depends on the language but for both java and C++ answer 3 is correct.
3 0
3 years ago
Which statement describes a disadvantage of e-government?
kicyunya [14]

Answer:

Setting up and maintaining the online systems can be expensive

Explanation:

4 0
4 years ago
How many fragments are generated?
Sedaia [141]

Answer:

The answer is B.4 hope this helps

3 0
3 years ago
Plato I need answers asap will
Alja [10]

Answer:

Thanks for the points  

Explanation:

3 0
3 years ago
Write a static method called bothStart that allows the user to input two Strings and returns the String that is the longest subs
marishachu [46]

Answer:

  1.    public static String bothStart(String text1, String text2){
  2.        String s = "";
  3.        if(text1.length() > text2.length()) {
  4.            for (int i = 0; i < text2.length(); i++) {
  5.                if (text1.charAt(i) == text2.charAt(i)) {
  6.                    s += text1.charAt(i);
  7.                }else{
  8.                    break;
  9.                }
  10.            }
  11.            return s;
  12.        }else{
  13.            for (int i = 0; i < text1.length(); i++) {
  14.                if (text1.charAt(i) == text2.charAt(i)) {
  15.                    s += text1.charAt(i);
  16.                }else{
  17.                    break;
  18.                }
  19.            }
  20.            return s;
  21.        }
  22.    }

Explanation:

Let's start with creating a static method <em>bothStart()</em> with two String type parameters, <em>text1 </em>&<em> text2</em> (Line 1).  

<em />

Create a String type variable, <em>s,</em> which will hold the value of the longest substring that both inputs start with the same character (Line 2).

There are two possible situation here: either <em>text1 </em>longer than<em> text2 </em>or vice versa. Hence, we need to create if-else statements to handle these two position conditions (Line 4 & Line 13).

If the length of<em> text1</em> is longer than <em>text2</em>, the for-loop should only traverse both of strings up to the length of the <em>text2 </em>(Line 5). Within the for-loop, we can use<em> charAt()</em> method to extract individual character from the<em> text1</em> & <em>text2 </em>and compare with each other (Line 15). If they are matched, the character should be joined with the string s (Line 16). If not, break the loop.

The program logic from (Line 14 - 20) is similar to the code segment above (Line 4 -12) except for-loop traverse up to the length of <em>text1 .</em>

<em />

At the end, return the s as output (Line 21).

5 0
3 years ago
Other questions:
  • Anyone have good websites to cure boredom
    10·2 answers
  • The main purpose of a constructor is to initialize the data members at the moment that an object is created. true or false?
    8·1 answer
  • __________ is a collection of formatting options—such as a frame, a rounded shape, and a shadow—that changes a picture’s overall
    5·1 answer
  • What’s the screen that displays results from typing text, performing calculations or running programs?
    9·1 answer
  • )In a graph represented by adjacency matrix u can find all the neighbours of a given vertices in ____Operations
    6·1 answer
  • Write a structured algorithm that prompts the
    9·1 answer
  • David wanted to build a Temple for God in________
    10·2 answers
  • There are main type of memory
    7·1 answer
  • 5. Played electronically by manipulating images on a television screen produced by a
    15·1 answer
  • Define computer memory and write it's type ​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!