Python for Beginners: The Ultimate Crash Course to Learn Python in One Week with Step-by-Step Guidance and Hands-On Exercises (Data Science Mastery Book 1) by Andrew Park
Author:Andrew Park [Park, Andrew]
Language: eng
Format: azw3, epub
Published: 2020-06-25T16:00:00+00:00
Program Code Resolution:
Line 10: Enter a year, but remember to call the int () function to convert it to an integer type.
Line 12-15: Judge whether it is a leap year.
Condition 1: every 4 leaps (divisible by 4) and every 100 leaps (not divisible by 100).
Condition 2: every 400 leaps (divisible by 400). One of the two conditions is a leap year. Readers are asked to inquire whether the following years are leap years: 1900 (flat year), 1996 (leap year), 2004 (leap year), 2017 (flat year), 2400 (leap year).
Multiple Choices
If there is more than one conditional judgment expression, elif conditional statement can be added. Elif is like the abbreviation of "else if." Although using multiple if conditional statements can solve the problem of executing different program blocks under various conditions, it is still not simple enough. Then, elif conditional statements can be used, and the readability of the program can be improved.
Note that if the statement is a logical "necessity" in our program. Elif and else do not necessarily follow, so there are three situations: if, if/else, if/elif/else.
The format is as follows:
If condition judgment
Expression 1:
# If the conditional judgment expression 1 holds, the program statement in this program block is executed
Elif condition judgment
Expression 2:
# If the conditional judgment expression 2 holds, execute the program statement in this program block
Else:
# If none of the above conditions hold, execute the program statement in this program block,
For example:
If first==second:
# If first equals second, execute the program statement in this program block
Elif first>second:
# If first is greater than second, execute the program statement in this program block
Else:
# if first is not equal to second and first is less than second, execute the program statement in this program block.
The following example program is used to practice the use of IF multiple selection. The purpose of the sample program is to detect the current time to decide which greeting to use.
[sample procedure: currentTime.py]
Detects the current time to decide which greeting
01 # -*- coding: utf-8 -*-
02 """
03 Program Name: Detect the current time to decide which greeting to use
04 Topic Requirements:
05 Judging from the current time (24-hour system)
06 5~10:59, output "good morning"
07 11~17:59, output "good afternoon"
08 18~4:59, output "good night"
09 """
11 import time
13 print ("current time: {}.” format (time.strftime ("%h:% m:% s"))
14 h = int( time.strftime("%H") )
16 if h>5 and h < 11:
17 print ("good morning!" )
18 elif h >= 11 and h<18:
19 print ("good afternoon!" )
20 else:
21 print ("good night!")
The execution results of the program will be shown on the screen.
The output shows the current time in the sample program to judge whether it is morning, afternoon, or evening, and then displays the appropriate greeting. Python's time module provides various functions related to time. The Time module is a module in Python's standard module library.
Before using it, you need to use the import instruction to import and then call the strftime function to format the time into the format we want. For example, the following program statement is used to obtain the current time.
import time
Time.strftime ("%h:% m:% s")
# 18: 36: 16 (6:36:16 p.
Download
Python for Beginners: The Ultimate Crash Course to Learn Python in One Week with Step-by-Step Guidance and Hands-On Exercises (Data Science Mastery Book 1) by Andrew Park.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9904)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9785)
The Mikado Method by Ola Ellnestam Daniel Brolund(9769)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8282)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7771)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7756)
Grails in Action by Glen Smith Peter Ledbrook(7686)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7550)
Windows APT Warfare by Sheng-Hao Ma(6773)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6499)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6399)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6367)
Kotlin in Action by Dmitry Jemerov(5048)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4313)
Functional Programming in JavaScript by Mantyla Dan(4037)
Solidity Programming Essentials by Ritesh Modi(3972)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3755)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3699)
The Ultimate iOS Interview Playbook by Avi Tsadok(3675)
