Question
One of the key elements of designing a good program is to allow the user(s) to interact with it. You can do so by asking
One of the key elements of designing a good program is to allow the user(s) to interact with it. You can do so by asking the user to input a file name, a string representing a DNA sequence, or just a number. These input that are coming in from the user get stored in variables, and make your program more interactive. They also allow you writing a general program that can work for any input (the user (or you) can run your program 100 times and each time input a different DNA sequence for instance).
The Python function to ask for use input, is simply called input()
Here is an example of how it can be used:
DNA = input("Enter a DNA sequence")
When you run this, you will see the string "Enter a DNA sequence", followed by a blinking line. That means Python is waiting for you to type in something! Once you type in a bunch of characters and hit enter, Python will grab what you typed and assign it to the variable DNA. So the string the user typed is now stored in memory and can be accessed by using the name DNA.
Here is an exercise:
Ask a user for 5 number. Use the input function, and store each number in a variable. Then calculate the sum and average of the numbers. Print out both the sum and average to the screen.
Post your code and the results of your calculation here
Note: No need to use a loop here, just ask the user 5 times by using 5 input() functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started