Exercise 29: What If

people = 20
cats = 30
dogs = 15
if people < cats:
  print "Too many cats! The world is doomed!"
if people > cats:
  print "Not many cats! The world is saved!"
if people < dogs:
  print "The world is drooled on!"
if people > dogs:
  print "The world is dry!"
dogs += 5
if people >= dogs:
  print "People are greater than or equal to dogs."
if people <= dogs:
  print "People are less than or equal to dogs."
if people == dogs:
  print "People are dogs."
时间: 2025-01-15 09:44:31

Exercise 29: What If的相关文章

Python Index

Table Of ContentsThe Hard Way Is EasierExercise 0: The SetupExercise 1: A Good First ProgramExercise 2: Comments And Pound CharactersExercise 3: Numbers And MathExercise 4: Variables And NamesExercise 5: More Variables And PrintingExercise 6: Strings

Bit Twiddling Hacks

http://graphics.stanford.edu/~seander/bithacks.html Bit Twiddling Hacks By Sean Eron Anderson[email protected] Individually, the code snippets here are in the public domain (unless otherwise noted) — feel free to use them however you please. The aggr

判断一个整数中有多少bit为1

Counting bits set (naive way) unsigned int v; // count the number of bits set in vunsigned int c; // c accumulates the total bits set in v for (c = 0; v; v >>= 1){  c += v & 1;} The naive approach requires one iteration per bit, until no more bi

[翻译]位运算暗黑魔导书

原文地址:http://graphics.stanford.edu/~seander/bithacks.html 有本书叫hack's delight也是主讲位运算的. 下面正文开始翻译吧,不定时更新. 声明: 如无特殊说明,所有的代码段都是不受版权限制的,如果喜欢,大家可以随便使用.文章内容由Sean Eron Anderson收集整理于1997-2005年.位运算的相关代码.说明以及分类希望能够给大家带来帮助,但是不对于该内容是否适合特定用途提供任何担保(or授权?).截止2005年5月5日

Pyqt5_QWidget

QWidget常用方法: Qwidget.size()#获得客户区的大小 QWidget.width().QWidget.height()#获得客户区的宽度与高度 #设置不可以变宽.高 QWidget.setFixedWidth(int width) QWidget.setFixedHeight(int height) QWidget.setFixedSize(Qsize size) QWidget.setFixedSize(int width,int height) #同时改变大小和位置 QW

Exercise 3.3 Calculate a discounted price

Exercise 3-3. Write a program that will calculate the price for a quantity entered from the keyboard, given that the unit price is $5 and there is a discount of 10 percent for quantities over 30 and a 15 percent discount for quantities over 50. 1 //

[Usaco2010 Dec]Exercise 奶牛健美操

[Usaco2010 Dec]Exercise 奶牛健美操 题目 Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点之间恰好有一条简单路径.简单的说来, 这些点的布局就是一棵树,且每条边等长,都为1. 对于给定的一个奶牛路径集合,精明的奶牛们会计算出任意点对路径的最大值, 我们称之为这个路径集合的直径.如果直径太大,奶牛们就会拒绝锻炼. Farmer John把每个点标记为1..V

&lt;&lt;C++ Primer&gt;&gt; 第四版Exercise Section 8.4.1 练习题

For exercise 8.6 1 // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <fstream> 7 #include <sstream> 8 9 using namespace std; 10 11 12 void print(istream &in) 13 { 14

*Exercise 5.1 Summing reciprocals of five values

Exercise 5-1. Write a program that will read five values of type double from the keyboardand store them in an array. Calculate the reciprocal of each value (the reciprocal ofvalue x is 1.0/x) and store it in a separate array. Output the values of the