SlideShare a Scribd company logo
1 of 3
Problem 1: Write a short program in Python that turns on all
LEDs, one at a time, in a looping fashion. When an LED is on,
it should stay on for 1 second. You will use a while loop to
identify the number of loops. You will have a total of 10 loops.
Note: n is initialized to 0 (zero). Inside the ‘while’ loop, make
sure to change the value of n by incrementing by 1. Also, print
the iteration count using the following line of code:
print(“Iteration: “,n). Finish the code block:
#testing a while loop
#import GPIO library
#import time library
import RPi.GPIO as GPIO
import time
#Global variables
N = 0
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT) #red LED
GPIO.setup(11,GPIO.OUT)#green LED
GPIO.setup(13,GPIO.OUT)#yellow LED
Problem 2: Problem 2 is going to take you some time to think
through and write. Although not an extensively long program, it
will require anywhere between 20 and 30 lines of code. For this
reason, I am only giving you 2 problems for homework. Write a
short program in Python that turns on an LED based on the
answer to a math calculation. Your program should do the
following:
1. Print: Say hello to the end user and tell the end user that the
program is designed to add 2 integers.
2. Print: Tell the end user that – if the answer is less than 10,
the red LED will turn on.
3. Print: Tell the end user that = if the answer is between (and
inclusive) 10 and 30, the yellow LED will turn on.
4. Print: Tell the end user that – if the answer is greater than 30,
the green LED will turn on.
5. Prompt the end user for 2 variables inputs, one at a time.
6. Calculate the addition problem.
7. Use an ‘if, else-if’ structure as described below.
Note, to ask the end user for an int input value, write the
following code:
x = int(input(“Enter a number to be added: “))
y = int(input(“Enter another number to be added: ))
Note, to use the if-else statement in Python, do the following:
If(answer <= 10):
Elif(answer > 10 or answer < 30):
Elif(answer >= 30):
PS Do not forget the ‘:’ (colon) at the end of these lines of
code!
Finish the code block:
#import GPIO library
#import time library
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT) #red LED
GPIO.setup(11,GPIO.OUT)#green LED
GPIO.setup(13,GPIO.OUT)#yellow LED
Problem 1 Write a short program in Python that turns on all LEDs,.docx

More Related Content

Similar to Problem 1 Write a short program in Python that turns on all LEDs,.docx

Temperature sensor with raspberry pi
Temperature sensor with raspberry piTemperature sensor with raspberry pi
Temperature sensor with raspberry piSantosh Kumar Kar
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxgerardkortney
 
Solved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ ExamsSolved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ ExamsMuhammadTalha436
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course BasicNaiyan Noor
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docxmelbruce90096
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdfT17Rockstar
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & ConditionsEbad ullah Qureshi
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 

Similar to Problem 1 Write a short program in Python that turns on all LEDs,.docx (20)

lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Temperature sensor with raspberry pi
Temperature sensor with raspberry piTemperature sensor with raspberry pi
Temperature sensor with raspberry pi
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
Solved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ ExamsSolved Practice Problems For the C++ Exams
Solved Practice Problems For the C++ Exams
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
 
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
Week 2PRG 218   Variables and Input and Output OperationsWrite.docxWeek 2PRG 218   Variables and Input and Output OperationsWrite.docx
Week 2PRG 218 Variables and Input and Output OperationsWrite.docx
 
Raspberry pi led blink
Raspberry pi led blinkRaspberry pi led blink
Raspberry pi led blink
 
C101-PracticeProblems.pdf
C101-PracticeProblems.pdfC101-PracticeProblems.pdf
C101-PracticeProblems.pdf
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
 
C# Loops
C# LoopsC# Loops
C# Loops
 
P3
P3P3
P3
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 

More from sleeperharwell

For this assignment, review the articleAbomhara, M., & Koie.docx
For this assignment, review the articleAbomhara, M., & Koie.docxFor this assignment, review the articleAbomhara, M., & Koie.docx
For this assignment, review the articleAbomhara, M., & Koie.docxsleeperharwell
 
For this assignment, provide your perspective about Privacy versus N.docx
For this assignment, provide your perspective about Privacy versus N.docxFor this assignment, provide your perspective about Privacy versus N.docx
For this assignment, provide your perspective about Privacy versus N.docxsleeperharwell
 
For this assignment, provide your perspective about Privacy vers.docx
For this assignment, provide your perspective about Privacy vers.docxFor this assignment, provide your perspective about Privacy vers.docx
For this assignment, provide your perspective about Privacy vers.docxsleeperharwell
 
For this Assignment, read the case study for Claudia and find two to.docx
For this Assignment, read the case study for Claudia and find two to.docxFor this Assignment, read the case study for Claudia and find two to.docx
For this Assignment, read the case study for Claudia and find two to.docxsleeperharwell
 
For this assignment, please start by doing research regarding the se.docx
For this assignment, please start by doing research regarding the se.docxFor this assignment, please start by doing research regarding the se.docx
For this assignment, please start by doing research regarding the se.docxsleeperharwell
 
For this assignment, please discuss the following questionsWh.docx
For this assignment, please discuss the following questionsWh.docxFor this assignment, please discuss the following questionsWh.docx
For this assignment, please discuss the following questionsWh.docxsleeperharwell
 
For this assignment, locate a news article about an organization.docx
For this assignment, locate a news article about an organization.docxFor this assignment, locate a news article about an organization.docx
For this assignment, locate a news article about an organization.docxsleeperharwell
 
For this assignment, it requires you Identifies the historic conte.docx
For this assignment, it requires you Identifies the historic conte.docxFor this assignment, it requires you Identifies the historic conte.docx
For this assignment, it requires you Identifies the historic conte.docxsleeperharwell
 
For this assignment, create a framework from which an international .docx
For this assignment, create a framework from which an international .docxFor this assignment, create a framework from which an international .docx
For this assignment, create a framework from which an international .docxsleeperharwell
 
For this assignment, create a 15-20 slide digital presentation in tw.docx
For this assignment, create a 15-20 slide digital presentation in tw.docxFor this assignment, create a 15-20 slide digital presentation in tw.docx
For this assignment, create a 15-20 slide digital presentation in tw.docxsleeperharwell
 
For this assignment, you are to complete aclinical case - narrat.docx
For this assignment, you are to complete aclinical case - narrat.docxFor this assignment, you are to complete aclinical case - narrat.docx
For this assignment, you are to complete aclinical case - narrat.docxsleeperharwell
 
For this assignment, you are to complete aclinical case - narr.docx
For this assignment, you are to complete aclinical case - narr.docxFor this assignment, you are to complete aclinical case - narr.docx
For this assignment, you are to complete aclinical case - narr.docxsleeperharwell
 
For this assignment, you are provided with four video case studies (.docx
For this assignment, you are provided with four video case studies (.docxFor this assignment, you are provided with four video case studies (.docx
For this assignment, you are provided with four video case studies (.docxsleeperharwell
 
For this assignment, you are going to tell a story, but not just.docx
For this assignment, you are going to tell a story, but not just.docxFor this assignment, you are going to tell a story, but not just.docx
For this assignment, you are going to tell a story, but not just.docxsleeperharwell
 
For this assignment, you are asked to prepare a Reflection Paper. Af.docx
For this assignment, you are asked to prepare a Reflection Paper. Af.docxFor this assignment, you are asked to prepare a Reflection Paper. Af.docx
For this assignment, you are asked to prepare a Reflection Paper. Af.docxsleeperharwell
 
For this assignment, you are asked to prepare a Reflection Paper. .docx
For this assignment, you are asked to prepare a Reflection Paper. .docxFor this assignment, you are asked to prepare a Reflection Paper. .docx
For this assignment, you are asked to prepare a Reflection Paper. .docxsleeperharwell
 
For this assignment, you are asked to conduct some Internet research.docx
For this assignment, you are asked to conduct some Internet research.docxFor this assignment, you are asked to conduct some Internet research.docx
For this assignment, you are asked to conduct some Internet research.docxsleeperharwell
 
For this assignment, you are a professor teaching a graduate-level p.docx
For this assignment, you are a professor teaching a graduate-level p.docxFor this assignment, you are a professor teaching a graduate-level p.docx
For this assignment, you are a professor teaching a graduate-level p.docxsleeperharwell
 
For this assignment, we will be visiting the PBS website,Race  .docx
For this assignment, we will be visiting the PBS website,Race  .docxFor this assignment, we will be visiting the PBS website,Race  .docx
For this assignment, we will be visiting the PBS website,Race  .docxsleeperharwell
 
For this assignment, the student starts the project by identifying a.docx
For this assignment, the student starts the project by identifying a.docxFor this assignment, the student starts the project by identifying a.docx
For this assignment, the student starts the project by identifying a.docxsleeperharwell
 

More from sleeperharwell (20)

For this assignment, review the articleAbomhara, M., & Koie.docx
For this assignment, review the articleAbomhara, M., & Koie.docxFor this assignment, review the articleAbomhara, M., & Koie.docx
For this assignment, review the articleAbomhara, M., & Koie.docx
 
For this assignment, provide your perspective about Privacy versus N.docx
For this assignment, provide your perspective about Privacy versus N.docxFor this assignment, provide your perspective about Privacy versus N.docx
For this assignment, provide your perspective about Privacy versus N.docx
 
For this assignment, provide your perspective about Privacy vers.docx
For this assignment, provide your perspective about Privacy vers.docxFor this assignment, provide your perspective about Privacy vers.docx
For this assignment, provide your perspective about Privacy vers.docx
 
For this Assignment, read the case study for Claudia and find two to.docx
For this Assignment, read the case study for Claudia and find two to.docxFor this Assignment, read the case study for Claudia and find two to.docx
For this Assignment, read the case study for Claudia and find two to.docx
 
For this assignment, please start by doing research regarding the se.docx
For this assignment, please start by doing research regarding the se.docxFor this assignment, please start by doing research regarding the se.docx
For this assignment, please start by doing research regarding the se.docx
 
For this assignment, please discuss the following questionsWh.docx
For this assignment, please discuss the following questionsWh.docxFor this assignment, please discuss the following questionsWh.docx
For this assignment, please discuss the following questionsWh.docx
 
For this assignment, locate a news article about an organization.docx
For this assignment, locate a news article about an organization.docxFor this assignment, locate a news article about an organization.docx
For this assignment, locate a news article about an organization.docx
 
For this assignment, it requires you Identifies the historic conte.docx
For this assignment, it requires you Identifies the historic conte.docxFor this assignment, it requires you Identifies the historic conte.docx
For this assignment, it requires you Identifies the historic conte.docx
 
For this assignment, create a framework from which an international .docx
For this assignment, create a framework from which an international .docxFor this assignment, create a framework from which an international .docx
For this assignment, create a framework from which an international .docx
 
For this assignment, create a 15-20 slide digital presentation in tw.docx
For this assignment, create a 15-20 slide digital presentation in tw.docxFor this assignment, create a 15-20 slide digital presentation in tw.docx
For this assignment, create a 15-20 slide digital presentation in tw.docx
 
For this assignment, you are to complete aclinical case - narrat.docx
For this assignment, you are to complete aclinical case - narrat.docxFor this assignment, you are to complete aclinical case - narrat.docx
For this assignment, you are to complete aclinical case - narrat.docx
 
For this assignment, you are to complete aclinical case - narr.docx
For this assignment, you are to complete aclinical case - narr.docxFor this assignment, you are to complete aclinical case - narr.docx
For this assignment, you are to complete aclinical case - narr.docx
 
For this assignment, you are provided with four video case studies (.docx
For this assignment, you are provided with four video case studies (.docxFor this assignment, you are provided with four video case studies (.docx
For this assignment, you are provided with four video case studies (.docx
 
For this assignment, you are going to tell a story, but not just.docx
For this assignment, you are going to tell a story, but not just.docxFor this assignment, you are going to tell a story, but not just.docx
For this assignment, you are going to tell a story, but not just.docx
 
For this assignment, you are asked to prepare a Reflection Paper. Af.docx
For this assignment, you are asked to prepare a Reflection Paper. Af.docxFor this assignment, you are asked to prepare a Reflection Paper. Af.docx
For this assignment, you are asked to prepare a Reflection Paper. Af.docx
 
For this assignment, you are asked to prepare a Reflection Paper. .docx
For this assignment, you are asked to prepare a Reflection Paper. .docxFor this assignment, you are asked to prepare a Reflection Paper. .docx
For this assignment, you are asked to prepare a Reflection Paper. .docx
 
For this assignment, you are asked to conduct some Internet research.docx
For this assignment, you are asked to conduct some Internet research.docxFor this assignment, you are asked to conduct some Internet research.docx
For this assignment, you are asked to conduct some Internet research.docx
 
For this assignment, you are a professor teaching a graduate-level p.docx
For this assignment, you are a professor teaching a graduate-level p.docxFor this assignment, you are a professor teaching a graduate-level p.docx
For this assignment, you are a professor teaching a graduate-level p.docx
 
For this assignment, we will be visiting the PBS website,Race  .docx
For this assignment, we will be visiting the PBS website,Race  .docxFor this assignment, we will be visiting the PBS website,Race  .docx
For this assignment, we will be visiting the PBS website,Race  .docx
 
For this assignment, the student starts the project by identifying a.docx
For this assignment, the student starts the project by identifying a.docxFor this assignment, the student starts the project by identifying a.docx
For this assignment, the student starts the project by identifying a.docx
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Problem 1 Write a short program in Python that turns on all LEDs,.docx

  • 1. Problem 1: Write a short program in Python that turns on all LEDs, one at a time, in a looping fashion. When an LED is on, it should stay on for 1 second. You will use a while loop to identify the number of loops. You will have a total of 10 loops. Note: n is initialized to 0 (zero). Inside the ‘while’ loop, make sure to change the value of n by incrementing by 1. Also, print the iteration count using the following line of code: print(“Iteration: “,n). Finish the code block: #testing a while loop #import GPIO library #import time library import RPi.GPIO as GPIO import time #Global variables N = 0 GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) #red LED GPIO.setup(11,GPIO.OUT)#green LED GPIO.setup(13,GPIO.OUT)#yellow LED Problem 2: Problem 2 is going to take you some time to think through and write. Although not an extensively long program, it will require anywhere between 20 and 30 lines of code. For this reason, I am only giving you 2 problems for homework. Write a short program in Python that turns on an LED based on the answer to a math calculation. Your program should do the following: 1. Print: Say hello to the end user and tell the end user that the program is designed to add 2 integers.
  • 2. 2. Print: Tell the end user that – if the answer is less than 10, the red LED will turn on. 3. Print: Tell the end user that = if the answer is between (and inclusive) 10 and 30, the yellow LED will turn on. 4. Print: Tell the end user that – if the answer is greater than 30, the green LED will turn on. 5. Prompt the end user for 2 variables inputs, one at a time. 6. Calculate the addition problem. 7. Use an ‘if, else-if’ structure as described below. Note, to ask the end user for an int input value, write the following code: x = int(input(“Enter a number to be added: “)) y = int(input(“Enter another number to be added: )) Note, to use the if-else statement in Python, do the following: If(answer <= 10): Elif(answer > 10 or answer < 30): Elif(answer >= 30): PS Do not forget the ‘:’ (colon) at the end of these lines of code! Finish the code block: #import GPIO library #import time library import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) #red LED GPIO.setup(11,GPIO.OUT)#green LED GPIO.setup(13,GPIO.OUT)#yellow LED