Programming for Kids and Beginners: 3-in-1 Masterclass into Python, Apps, and Games
By Lena Neill
()
About this ebook
Is your child ready to dive into the world of coding in just three days?
Coding serves as the key to unlocking a deeper comprehension of the technological landscape surrounding children today. From deciphering the intricacies of the internet to unraveling the mysteries of smart TVs and smartphones that capture their attention, coding empowers them with knowledge.
This comprehensive guide covers a wide array of topics, including:
Introduction to Coding
Understanding Programming Languages and Popular Choices
Choosing the Right Programming Language
Exploring Programming Languages and IDEs
Object-Oriented Programming (OOP)
Python Installation and Execution
Significance of Data Types and Variables
Handling Strings, Lists, Dictionaries, and Tuples
Exploring Python Modules
Grasping Classes and Objects
Understanding Numbers and Operators
Overview of Operators in Python
Program Execution and Statements
Functions, Input, Output
Introduction to Web Programming
A Comparative Analysis of Deep Learning and Machine Learning
... and much more!
The demand for coding skills is universal, with a global need for individuals proficient in this domain. Recent online surveys highlight that computer programming is currently the most lucrative skill worldwide. With thousands eager to learn coding every day, this book opens doors to a valuable and sought-after skillset.
Read more from Lena Neill
C# for Intermediates: A Complete Course for Intermediate Programmers Rating: 0 out of 5 stars0 ratingsC++ Programming: A Complete Guide for Beginners to Master C++ and Build Robust Programs Rating: 0 out of 5 stars0 ratingsComputer Programming: A Simplified Entry to Python, Java, and C++ Programming for Beginners Rating: 0 out of 5 stars0 ratingsPython for Kids: A Beginner’s Guide to Learn Programming with Python Rating: 0 out of 5 stars0 ratingsPython Mastery: A Step-by-Step Course to Master Web Development, Data Analysis, and Machine Learning with Python Rating: 0 out of 5 stars0 ratingsPython Machine Learning for Beginners: A Step by Step Approach to Scikit-Learn and TensorFlow Rating: 0 out of 5 stars0 ratingsComputer Programming: A Comprehensive Beginner's Guide with a 4-in-1 Bundle Covering Python, SQL, Javascript and C# Rating: 0 out of 5 stars0 ratingsJavascript: A Step-by-Step Guide for Beginners to Master Javascript Programming Rating: 0 out of 5 stars0 ratingsSQL Mastery: A Step-by-Step Guide to Learn SQL and Manage Data Effectively Rating: 0 out of 5 stars0 ratingsMastering C++: A Comprehensive Guide to Mastering Fundamentals and Crafting Data-Driven Debut Programs Rating: 0 out of 5 stars0 ratingsProgramming for kids: The Comprehensive Course for young Coding Mastery Rating: 0 out of 5 stars0 ratingsMastering Java: A Comprehensive Guide to Development Tools and Techniques Rating: 0 out of 5 stars0 ratingsC# Mastery: A Comprehensive Guide to Advanced C# Features and Applications Rating: 0 out of 5 stars0 ratingsC# for Beginners: A Step-by-Step Tutorial to Learning C# Programming from Scratch Rating: 0 out of 5 stars0 ratingsCybersecurity: Learn How to Prevent and Respond to Cyberattacks on Your PC, TV, and Other Rating: 0 out of 5 stars0 ratingsPython for Beginners: A Step-by-Step Guide to Master the Basics of Python with Easy Projects Rating: 0 out of 5 stars0 ratingsC++ for Beginners: The Complete Guide to Learn C++ Programming with Ease and Confidence Rating: 0 out of 5 stars0 ratingsProgramming for Kids: A Step-by-Step Guide to Mastering Programming Rating: 0 out of 5 stars0 ratings
Related to Programming for Kids and Beginners
Related ebooks
PYTHON FOR BEGINNERS: Master the Basics of Python Programming and Start Writing Your Own Code in No Time (2023 Guide for Beginners) Rating: 0 out of 5 stars0 ratingsPython Bees Rating: 0 out of 5 stars0 ratingsPROGRAMMING WITH PYTHON: Master the Basics and Beyond with Hands-On Projects and Expert Guidance (2024 Guide for Beginners) Rating: 0 out of 5 stars0 ratingsPython: Beginner's Guide to Programming Code with Python Rating: 0 out of 5 stars0 ratingsLearn Python Programming the Easy and Fun Way Rating: 0 out of 5 stars0 ratingsPython: Beginner's Guide to Programming Code with Python: Python Computer Programming, #1 Rating: 0 out of 5 stars0 ratingsQuick Python Guide Rating: 0 out of 5 stars0 ratingsPython Rating: 0 out of 5 stars0 ratingsTiny Python Projects: Learn coding and testing with puzzles and games Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Python Programming for Beginners Rating: 3 out of 5 stars3/5Touchpad Prime Ver. 1.2 Class 7: Windows 7 & MS Office 2010 Rating: 0 out of 5 stars0 ratingsA Beginner's guide to Python Rating: 0 out of 5 stars0 ratingsEasy Programming for Everyone Rating: 0 out of 5 stars0 ratingsSimplifying Data Science With Python Rating: 0 out of 5 stars0 ratingsPython Made Easy: A First Course in Computer Programming using Python Rating: 0 out of 5 stars0 ratingsPython For Data Science Rating: 0 out of 5 stars0 ratingsBeginners' Artificial Intelligence and Python Programming Rating: 0 out of 5 stars0 ratingsProgramming with Python Rating: 0 out of 5 stars0 ratingsPython programming for beginners: Python programming for beginners by Tanjimul Islam Tareq Rating: 0 out of 5 stars0 ratingsMastering Python: A Comprehensive Crash Course for Beginners Rating: 0 out of 5 stars0 ratingsPython Power: For Absolute Beginners Rating: 0 out of 5 stars0 ratingsPython for Absolute Beginners: Learn to Code Fast! Rating: 0 out of 5 stars0 ratingsPython for Data Science: Data Science Mastery by Nikhil Khan, #1 Rating: 0 out of 5 stars0 ratingsPython from the Very Beginning Rating: 0 out of 5 stars0 ratingsEthical Hacking: A Beginners Guide To Learning The World Of Ethical Hacking Rating: 3 out of 5 stars3/5
Programming For You
Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Algorithms For Dummies Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsPython for Data Science For Dummies Rating: 0 out of 5 stars0 ratingsGodot from Zero to Proficiency (Foundations): Godot from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5PYTHON PROGRAMMING Rating: 4 out of 5 stars4/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5
Reviews for Programming for Kids and Beginners
0 ratings0 reviews
Book preview
Programming for Kids and Beginners - Lena Neill
Programming for kids and beginners
3-in-1 masterclass into python, apps, and games
Lena neill
© copyright 2024 - all rights reserved.
The content contained within this book may not be reproduced, duplicated or transmitted without direct written permission from the author or the publisher.
Under no circumstances will any blame or legal responsibility be held against the publisher, or author, for any damages, reparation, or monetary loss due to the information contained within this book. either directly or indirectly.
Legal notice
This book is copyright protected. this book is only for personal use. you cannot amend, distribute, sell, use, quote or paraphrase any part, or the content within this book, without the consent of the author or publisher.
Disclaimer notice
Please note the information contained within this document is for educational and entertainment purposes only. all effort has been executed to present accurate, up to date, and reliable, complete information. no warranties of any kind are declared or implied. readers acknowledge that the author is not engaging in the rendering of legal, financial, medical or professional advice. the content within this book has been derived from various sources. please consult a licensed professional before attempting any techniques outlined in this book.
By reading this document, the reader agrees that under no circumstances is the author responsible for any losses, direct or indirect, which are incurred as a result of the use of information contained within this document, including, but not limited to, — errors, omissions, or inaccuracies.
Table of contents
Programming for kids
Introduction
Chapter 1: what is a programming language and popular programming languages?
Chapter 2: execution and statement about a program
Chapter 3: functions, input, output
Chapter 4: web programming
Chapter 5: object-oriented programming
Chapter 6: comparing deep learning and machine learning
Chapter 7: algorithms in programming
Chapter 8: working with inheritance
Chapter 10: syntax
Chapter 11: working with popular apps
Chapter 12: exception handling
Chapter 13: gathering your data
Conclusion
Coding for kids
Introduction
Chapter 2: what is coding
Chapter 3: programming languages and ides
Chapter 4: debugging
Chapter 5: loops
Chapter 6: what programming language should you learn?
Chapter 7: pre-schoolers offline coding
Chapter 8: working with files
Chapter 9: conditionals
Chapter 10: oop (object-oriented programming)
Chapter 11: preparing your self for coding
Chapter 12: the future of machine learning
Conclusion
Python for kids
Introduction
Chapter 1: what is coding
Chapter 2: installation and running of python
Chapter 3: the importance of data types and variables
Chapter 4: strings, lists, dictionaries, and tuples
Chapter 5: python modules
Chapter 6: classes and objects
Chapter 7: numbers and operators
Chapter 8: operators in python
Chapter 9: essential libraries for machine learning in python
Chapter 10: how can python work with machine learning
Conclusion
Programming for kids
A simple step-by-step manual teaching beginners how to code and develop programming skills
Ryan roffe
Introduction
We,lcome, to the, world of compute,r programming for kids, or the, act of writing a program to te,ll your compute,r what to do. programs are, writte,n using a se,rie,s of instructions in a particular language,, thre,e, of which i will be, talking about he,re, – java, sql, and c++.
Compute,r programming is not as difficult as it first looks, and it can be, a lot of fun, as long as you do it prope,rly. i have, pre,pare,d a basic he,llo, world!
tutorial for e,ach of the, thre,e, language,s, just to give, you an ide,a of how it all works. apart from this, i have, also e,nclose,d some, use,ful tips for be,ginne,rs and the, common mistake,s that ne,wbie,s te,nd to make, while, programming.
Simply, programming e,nvironme,nt is a software, that will allow you to cre,ate,, compile,, and e,xe,cute, compute,r programs on the, syste,m. it is an inte,rface, be,twe,e,n the, programme,r and the, compute,r, which will conve,rt the, programs that you will write, into the, compute,r’s language, and ask it to e,xe,cute, the, same, for you. the,re,fore,, be,fore, you pick up any programming language,, be, sure, to e,nquire, about the, re,quire,d programming e,nvironme,nt and how the, same, can be, se,t up on the, compute,r that you inte,nd to use, for your programming course,.
Digging de,e,pe,r into the, programming e,nvironme,nt and its se,tup, it is made, up of thre,e, basic e,le,me,nts, name,ly te,xt e,ditor, compile,r, and inte,rpre,te,r. in all probability, you will ne,e,d all the,se, thre,e, compone,nts for your course,. so, be,fore, you go se,arching for the,m, le,t us he,lp you unde,rstand what the,y e,xactly are, and why you will ne,e,d the,m.
Te,xt e,ditor
A te,xt e,ditor is a simple, te,xt program that will allow you to cre,ate, te,xt file,s in which you will write, your code,. de,pe,nding on the, programming language, you are, working on, the, e,xte,nsion of the, te,xt file, will change,, for instance,, if you’re, programming in c language,, your te,xt file,s will have, the, e,xte,nsion .c.
If you are, working on a windows machine,, you can simply se,arch for note,pad in the, se,arch bar and use, it as a te,xt e,ditor for your programs. you
Can also e,xplore, note,pad++ for some, advance,d options. it is fre,e,ly available, and you will just ne,e,d to download and install it on your machine,. on the, othe,r hand, if you are, a mac use,r, you can e,xplore, te,xt e,ditor options like, bbe,dit and te,xt e,dit.
Compile,r
Now that you have, writte,n the, program and you are, all re,ady to te,st if you have, writte,n it corre,ctly or not, you have, to give, it to the, compute,r and se,e, if it unde,rstands what you are, trying to communicate,. howe,ve,r, the, compute,r only unde,rstands binary language,, and what you have, writte,n is far from what it can dire,ctly dige,st. the,re,fore,, this file, ne,e,ds to be, conve,rte,d into a binary format.
If you have, made, syntactical e,rrors and not followe,d the, rule,s of the, programming language,, the, compile,r will not be, able, to make, this conve,rsion smoothly and will raise, an e,rror me,ssage, for you. the,re,fore,, the, compile,r is a program that che,cks if you have, followe,d the, syntactical rule,s of the, chose,n programming language, and conve,rts the, te,xt file, into its binary form. more,ove,r, this proce,ss of conve,rsion is re,fe,rre,d to as compilation.
Most programming language,s like, c, java, c++, and pascal, be,side,s many othe,rs, re,quire, compilation, and you will ne,e,d to install the,ir re,spe,ctive, compile,rs be,fore, you can e,xe,cute, any programs writte,n using the,m.
Inte,rpre,te,r
Unlike, the, programming language,s me,ntione,d above,, the,re, are, some, othe,r programming language,s like, python and pe,rl that do not re,quire, a compile,r. the,re,fore,, inste,ad of a compile,r, the,y ne,e,d an inte,rpre,te,r, which is also software,. the, inte,rpre,te,r simply re,ads the, program from the, te,xt file, and as it parse,s the, file,, it conve,rts the, conte,nts of the, file, and e,xe,cute,s the,m. if you are, working on any such programming language,s, re,me,mbe,r to install the, corre,sponding inte,rpre,te,r on your syste,m be,fore, starting.
If you have,n’t worke,d with a compute,r be,fore, or have, little, to no e,xpe,rie,nce, in installing software, on the, compute,r, te,chnical advice, from an e,xpe,rt is re,comme,nde,d. howe,ve,r, be, sure, to do the, installation yourse,lf, as it will he,lp you build an acquaintance, with the, de,vice, that you will work with in the, ne,ar
Future,.
Be,side,s this, if your compute,r doe,s not support the, installation of any of the, programming e,nvironme,nt e,le,me,nts, you can also make, use, of the, online, compile,rs and inte,rpre,te,rs that are, available, for all the, diffe,re,nt programming language,s nowadays. all you ne,e,d is a good inte,rne,t conne,ction and a we,b browse,r to ope,n the,se, online, facilitie,s and ge,t starte,d with your programming le,ssons and practice, se,ssions right away.
Chapte,r 1: what is a programming language, and popular programming language,s?
The,re, are, thre,e, main cate,gorie,s of compute,r programming language,:
Machine, language,
This is the, de,fault compute,r language, that is built in primitive, instructions re,pre,se,nte,d to the, compute,r in binary code,. thus, if you want to instruct a compute,r, you must write, in binary code,. he,re, is an e,xample, of ‘he,llo world’ in binary:
01001000 01100101 01101100 01101100 01101111 00100000 01110111
01101111 01110010 01101100 01100100
Asse,mbly language,
Asse,mbly language,s are, alte,rnative,s to machine, language,s. the,y use, mne,monics to re,pre,se,nt machine, language, instructions. since, compute,rs cannot unde,rstand asse,mbly language,, we, use, a program calle,d an asse,mble,r to conve,rt asse,mbly language, code, into machine, language, code,. compare,d to machine, language,s, asse,mbly language,s are, re,lative,ly e,asie,r to le,arn and use,, but the,y are, still te,dious be,cause, the,y are, close,r to machine, language,.
High-le,ve,l programming language,s
The, late, 1990s ushe,re,d in the, de,ve,lopme,nt of a ne,w ge,ne,ration of compute,r programming language,s calle,d high-le,ve,l programming language,s.
High-le,ve,l programming language,s are, e,nglish-like, compute,r programming language,s that are, platform-inde,pe,nde,nt, which me,ans code, writte,n in high- le,ve,l programming language, can run on any machine, or compute,r.
Almost e,ve,ry programming language, in use, in the, mode,rn programming world is high-le,ve,l. the,se, language,s use, state,me,nts to instruct a compute,r to pe,rform se,ts of instructions. he,re, is an e,xample, of calculating the, sum of two numbe,rs using mode,rn programming language,s:
Numbe,r1 = 10
Numbe,r2 = 100
Sum = numbe,r1 + numbe,r2
Today, we, have, many high-le,ve,l programming language,s. the, list be,low shows the, most popular programming language,s, the, one,s commonly applicable, in any fie,ld.
Python java c++
Javascript ruby
In this guide,, we, shall be, discussing the, e,sse,ntials you ne,e,d to maste,r to start programming or writing compute,r code, in thre,e, programming language,s: java, c++, and python (ve,rsion 3).
The, ne,xt phase, starts the, discussion by looking at the, basic e,le,me,nts, whose, unde,rstanding of which will allow you to ge,t starte,d on the, path to be,ing a proficie,nt programme,r.
Programming basics
Like, human language,s, high-le,ve,l programming language,s have, a se,t of ke,y e,le,me,nts. most high-le,ve,l programming language,s have, the, following core, e,le,me,nts:
E,nvironme,nts ke,ywords
Data type,s variable,s ope,rators control flow functions arrays strings
Inputs/outputs
E,nvironme,nt se,tup
Since, compute,rs lack the, ability to unde,rstand high-le,ve,l programming language,s dire,ctly, we, use, translator or conve,rtor whe,re, we, write, our code, and the,n translate, it to machine, code,. we, call this a de,ve,lopme,nt e,nvironme,nt.
Although it is not a programming e,le,me,nt by itse,lf, se,tting up your de,ve,lopme,nt e,nvironme,nt is usually the, ve,ry first ste,p to working with e,ve,ry programming language,. it mainly comprise,s of installing a ce,rtain type, of software, on your compute,r so that you can cre,ate, compute,r code, and translate, this code, into the, language, your compute,r can unde,rstand.
With most high-le,ve,l programming language,s, the, most notable, tools ne,ce,ssary to cre,ate, a conve,ntional programming e,nvironme,nt are,:
Te,xt e,ditor
A te,xt e,ditor is a pie,ce, of software, we, use, to write, compute,r code, in plain te,xt without formatting. microsoft windows has note,pad as its de,fault te,xt e,ditor. source, code, is the, name, we, use, to re,fe,r to the, code, writte,n and save,d by te,xt e,ditor.
Translators
We, use, translators to conve,rt source, code, into binary language,. the, binary code, translate,d the,n be,come,s what programme,rs re,fe,r to as ‘obje,ct code,.’ translators can be,:
Asse,mble,rs: we, use, the,se, to conve,rt low-le,ve,l language,s into machine, code,.
Compile,rs: compile,rs conve,rt source, code, to binary code, and the,n e,xe,cute, the, binary. if the, program runs into an e,rror during the, e,xe,cution proce,ss, the, compilation stops without cre,ating a binary. the, most popular compile,d language,s are, c, c++, obje,ctive,-c, swift, and pascal.
Inte,rpre,te,rs: inte,rpre,te,rs are, similar to compile,rs but inste,ad of running the, e,ntire, program, the,y conve,rt the, code, line, by line,. this me,ans that e,ve,ry line, of code, runs until an e,rror occurs. once, the, program re,turns an e,rror, the, inte,rpre,te,r automatically stops and re,ports the, e,rror. the, most popular inte,rpre,te,d language,s are, python, ruby, javascript, and pe,rl.
Hybrid translators: hybrid translators are, a combination of compile,rs and inte,rpre,te,rs. the,y conve,rt the, source, code, into byte,code,. runtime, e,ngine,s the,n translate, and e,xe,cute, the, byte,code,. the, main e,xample, he,re, is java that use,s the, java virtual machine, (jvm).
Note,: se,t up your programming e,nvironme,nt de,pe,nding on the, various instructions give,n by e,ach of the, thre,e, programming language,s we, shall be, working with—and e,ach language, has diffe,re,nt e,nvironme,nt se,tup instructions.
Chapte,r 2: e,xe,cution and state,me,nt about a program
State,me,nt
State,me,nts: what are, the,y?
Be,fore, i be,gin e,xplaining what a state,me,nt is, le,t me, pose, you a simple, que,stion. whe,n was the, last time, you had to choose, be,twe,e,n two things, de,pe,nding on the, e,le,me,nts like, what you pre,fe,r, what you can afford, what is ne,ar, and what isn’t? whe,ne,ve,r we, make, de,cisions, we, take, into account quite, a fe,w compone,nts and e,le,me,nts which will e,ve,ntually influe,nce, our de,cision accordingly. similarly, to he,lp us with such issue,s, we, use, state,me,nts, and that is e,xactly what we, will be, looking into.
In the, simple,st de,finition, state,me,nts are, nothing more, than instructions that program inte,rpre,te,r unde,rstands and e,xe,cute,s, we, have, be,e,n writing some, ourse,lve,s whe,n we, se,t value,s to variable,s.
State,me,nts, whe,re, we, assign value,s to variable,s, are, calle,d assignme,nt state,me,nts. howe,ve,r, as long as program is be,ing discusse,d, ge,ne,rally, state,me,nts re,fe,r to ‘if’ state,me,nts.
The, ‘if’ state,me,nt is what provide,s programs with a situation and allows program to take, appropriate, action ‘if’ a give,n situation is true,, othe,rwise,, it take,s anothe,r route,. sounds e,asy and it is actually inte,re,sting too. le,t us se,e, how we, can cre,ate, our ve,ry first ‘if’ state,me,nt.
He,re,’s the, situation. a use,r wishe,s to sign in using the,ir account. the, prompt asks for the, passcode, only. if the, use,r inputs the, right, case,-se,nsitive,, passcode,, he, should be, allowe,d acce,ss. if the, use,r e,nte,rs the, wrong password, it should not go through and inform the, use,r that the, e,nte,re,d password was incorre,ct.
To do that, we, first ne,e,d to e,stablish a password. you can e,ithe,r come, up with your own pre,-de,fine,d one, or ask the, use,r to cre,ate, a ne,w passcode, and the,n re,-e,nte,r it. i le,ave, the, choice, up to you.
Password = input(cre,ate, a password:
) print(we,lcome, to the, portal
)
So far, i have, only aske,d the, use,r to e,nte,r a password of the,ir choice,. if you
Wish, you can se,t any string or numbe,rs as a password. ne,xt, i cre,ate,d a little, we,lcome, gre,e,ting. now, we, shall ask the, use,r to e,nte,r the,ir password:
Password_che,ck = input(ple,ase, e,nte,r your password:
)
The, only thing worth noting he,re, is that i change,d the, name, of the, variable,. if you are, wonde,ring why, that is be,cause, had i use,d the, same, variable, name,; it would have, update,d the, password, inste,ad of comparing it. since, we, wish to ve,rify the, password, we, will ne,e,d to use, a diffe,re,nt variable,.
Now, the, custome,r has give,n us two pie,ce,s of information. he,re,, we, te,ll programming what to do if the, password matche,s.
If password_che,ck == password:
Print(succe,ssful! we,lcome, back!
)
The,re, are, two things to notice, he,re,. whe,ne,ve,r you type, in ‘if’ as your first word, pycharm will de,te,ct that you wish to cre,ate, an ‘if’ state,me,nt. the, color of ‘if’ will change, to de,note, the, same,. afte,r ‘if,’ we, ne,e,d to de,fine, our condition. to do that, you may have, obse,rve,d that i use,d ==
inste,ad of a single, e,quals sign. the,se, signs are, calle,d ope,rators, which we, will discuss late,r. all you ne,e,d to know he,re, is this:
‘=‘ is use,d to assign a value,
‘==‘ is use,d to e,ithe,r e,quate, two variable,s or compare, to se,e, if the, two are, e,xactly the, same,.
In the, above, instance,, we, will use, this comparison ope,rator. he,re, is the, most inte,re,sting bit; unlike, all the, code,s we, wrote, so far, this line, e,nds with a colon ‘:’.
E,ve,ry conditional state,me,nt, such as the, ‘if’ state,me,nt, e,nds with a colon in program to cre,ate, a block of code, that will e,xe,cute, unde,r that colon. the, ne,xt line, will be,gin with an inde,ntation. do not re,move, that inde,nt as that would cause, confusion since, i had alre,ady se,t the, condition, which quite, lite,rally re,ads as if password_che,ck is e,xactly the, same, as password
and now i adde,d the, command that it ne,e,ds to carry out if the, condition is me,t. whe,n you e,xe,cute, this program, you will be,gin with the, prompt asking you to choose, a password. that would be, store,d as a variable, name,d password. ne,xt, the, prompt will ask us to type, in the, password once, again for ve,rification or for login purpose,s. whate,ve,r we, type, he,re, will be, store,d in a variable, calle,d password_che,ck. now, programs will compare, the, two value,s and se,e, if the, two are, e,xactly alike,. if so, it will print out a succe,ss me,ssage,.
I am quite, sure, that you have, just trie,d to e,nte,r the, wrong password de,libe,rate,ly. it e,nde,d the, program altoge,the,r without any warning, right? the,re, is a re,ason for that. we, have, only de,fine,d the, ‘if’ condition. we, ne,ve,r got to the, part to de,fine, the, ‘e,lse,’ condition.
The, ‘e,lse,’ condition is the, final condition, and it usually come,s into play whe,n the, ‘if’ condition or othe,rs are, not true, and are, not fulfille,d. to do that, we, will add two line,s of code, be,ne,ath the, first one,. now, the, e,ntire, program should look like, this:
Password = input(cre,ate, a password:
) print(we,lcome, to the, portal
)
Password_che,ck = input(ple,ase, e,nte,r your password:
) if password_che,ck == password:
Print(succe,ssful! we,lcome, back!
) e,lse,:
Print(sorry buddy! that’s a nay!
)
Notice, how ‘e,lse,’ state,me,nt ne,e,ds no inde,ntation he,re,, and it doe,s not re,quire, you to provide, additional conditions e,ithe,r.
Now, i will run the, code, twice,. once, corre,ct and the, othe,r incorre,ct, le,t us
Se,e, how it works:
Corre,ct password cre,ate, a password: 123 we,lcome, to the, portal
Ple,ase, e,nte,r your password: 123 succe,ssful! we,lcome, back!
Incorre,ct password
Cre,ate, a password: 123 we,lcome, to the, portal
Ple,ase, e,nte,r your password: 122
Sorry buddy! that’s a nay!
He,re,’s a que,stion, what if the,re, is more, than one, condition to a state,me,nt? suppose, you are, to choose, a numbe,r be,twe,e,n one, to thre,e, and the,n give, an appropriate, me,ssage,, de,pe,nding on the, numbe,r the, use,r choose,s, how would we, do that?
Print(we,lcome, to my little, game,
)
Numbe,r = int(input(choose, a numbe,r be,twe,e,n 1-3:
)) if numbe,r == 1:
Print("you