FOUNDATIONS OF PROGRAMMING : INTRODUCTION TO PROGRAMMING : 01.05 STRING INPUT

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

User Input in Python

# Input Sample def main(): firstName = input("enter your name: ") print("Hello, " + firstName + "!") main() output: Hello, Sarah!

Getting User Input in Python:

# Input Sample def main(): someVariable = input("What is your favorite animal?") print("Your favorite animal is " + someVariable + "." ) main() # Input Sample def main(): favAnimal=input("What is your favorite animal?") print("Your favorite animal is the " + favAnimal + "." ) main()

Using Pseudocode: Pseudocode with Input and Output

# Pseudocode Sample def main(): answer = input("What do computers like to eat?") print("You answered that computers like to eat " + answer + ".") print("If you answered chips, as in microchips, you are correct! Hahaha.") main() Output: You answered that computers like to eat code. If you answered chips, as in microchips, you are correct! Hahaha.

input()

Python has a built in function called input(). This allows programmers to create interactive statements to ask users for information. Important: To get input, the program must prompt the user. That's why you provide a string literal prompt like "Enter your name." or "Do you like Oreos?" to give the user some instructions.

This is what your code would look like if you wanted to ask a user for their name.

firstName = input("Hello! What is your name?") firstName: variable input : funciton ("Hello! What is your name?"): a string literal

pseudocode

pseudocode an outline of your code that goes through the steps individually in an easy-to-understand, human language Tips for Writing Good Pseudocode Use it to plan out your program, start to finish Outline your steps as clearly as possible Use everyday words, not Python code Use short phrases to describe the steps (ex. Input firstName, lastName) All pseudocode will look slightly different Make sure to review and make changes as necessary


Set pelajaran terkait

Academic Team Full Practice Set 9

View Set

Health Data Final - Jarvis (1 & 2)

View Set

ServSafe Food Manager Exam Review

View Set

Death of Marat (1793) Jacques Louis David

View Set

Fundamentals - Urinary Elimination

View Set

Chapter 58: Caring for Clients with Disorders of the Kidneys and Ureters

View Set

Level 24: Property Management - Chapter 2: Management Agreement

View Set

Primavera Economics Unit 2 Workbooks and Checkpoints

View Set

Trauma, Stressor-Related, and Dissociative Disorders

View Set