python输出九九乘法表儿歌_python学习:输出九九乘法表

输出九九乘法表

代码:

num1 = 1

while num1 <= 9:

num2 = 1

while num2 <= num1:

print(str(num2)+"*"+str(num1)+"="+str(num2*num1),end="\t")

num2 += 1

print()

num1 += 1

ps:“\t”为制表符;"\n"为换行。

执行结果:正序排列

代码修改:

num1 = 9

while num1 > 0:

num2 = 1

while num2 <= num1:

print(str(num2)+"*"+str(num1)+"="+str(num2*num1),end="\t")

num2 += 1

print()

num1 -= 1

执行结果:逆序排列

输出九九乘法表(Python、Java、C、C&plus;&plus;、JavaScript)

最近在学python的过程中,接触到了循环的知识,以及这个案例,于是写了下!感觉还不错,然后就用其它几种语言也试了下!! 接下来,就跟大家分享下实现方法!! 实现输出九九乘法表,主要用到的是循环的知识 ...

Python练习题 006:输出九九乘法表

[Python练习题 006] 输出九九乘法表 --------------------------------------------------- 照理这题不难,逻辑关系弄对了就好办,但数学渣的我 ...

JavaWeb 输出九九乘法表,三角形,菱形

For循环输出九九乘法表

题:使用For循环输出九九乘法表 解析: 1*1=1 1*2=2  2*2=4 1*3=3  2*3=6  3*3=9 .... 1*9=9  ........ .....9*9=81 可以看做j*i ...

python之打印九九乘法表

配置环境:python 3.6 python编辑器:pycharm 整理成代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- #九九乘法表 #分析:九 ...

shell脚本输出九九乘法表

#!/bin/bash#输出九九乘法表 for ((i=1;i<=9;i++)) do for ((j=1;j<=$i;j++)) do echo -n $j'x'$i=$(($i*$j) ...

python3: 简单4步骤输出九九乘法表

如何输出一个九九乘法表,使用python语言,嵌套循环,4行代码就可以实现,瞬间感觉python真的很简单~ 代码: for i in range(1,10): for j in range(1,i+ ...

Python中的九九乘法表(for循环)

用for循环写出的九九乘法表(包括函数的调用) #方向一 for i in range(1,10):    for j in range(1,i+1):        d = i * j        ...

使用JSP输出九九乘法表

在html网页中编写Java代码是,需要使用来编写,表示取等号后面的值,如就会输出hello. &lt ...

随机推荐

C&num;中的interface

接口(interface) 接口泛指实体把自己提供给外界的一种抽象化物(可以为另一实体),用以由内部操作分离出外部沟通方法,使其能被修改内部而不影响外界其他实体与其交互的方式. 接口实际上是一个约定: ...

APK瘦身实践

首发地址:http://www.jayfeng.com/2015/12/29/APK%E7%98%A6%E8%BA%AB%E5%AE%9E%E8%B7%B5/ 因为推广的需要,公司需要把APK的大小再 ...

PRML读书会第三章 Linear Models for Regression&lpar;线性基函数模型、正则化方法、贝叶斯线性回归等&rpar;

主讲人 planktonli planktonli(1027753147) 18:58:12  大家好,我负责给大家讲讲 PRML的第3讲 linear regression的内容,请大家多多指教,群 ...

MySQL中多表删除方法(转载)

如果您是才接触MySQL数据库的新人,那么MySQL中多表删除是您一定需要掌握的,下面就将为详细介绍MySQL中多表删除的方法,供您参考,希望对你学习掌握MySQL中多表删除能有所帮助. 1.从MyS ...

十款最佳Node&period;js MVC框架

十款最佳Node.js MVC框架摘要:Node.js是JavaScript中最为流行的框架之一,易于创建可扩展的Web应用.本文分享十款最佳的JavaScript框架. Node.js是JavaSc ...

启动Apache出现问题:一直停留在启动界面

问题描述:  由于需要php_curl模块,因此直接在php.ini文件将前面的分号去掉  ,但是重启Apache时出现:一直停留在启动界面,Apache无法正常启动,查看错误日志,显示如下: 解决方 ...

Python并发编程之从生成器使用入门协程(七)

大家好,并发编程 进入第七篇. 从今天开始,我们将开始进入Python的难点,那就是协程. 为了写明白协程的知识点,我查阅了网上的很多相关资料.发现很难有一个讲得系统,讲得全面的文章,导致我们在学习的 ...

Vue语法学习第五课——条件渲染

① v-if .v-else-if .v-else

A

KVM虚拟化技术(二)KVM介绍

KVM:Kernel Virtual Machine KVM是基于虚拟化扩展的x86硬件,是Linux完全原生的全虚拟化解决方案.部分半虚拟化支持,主要是通过半虚拟网络驱动程序的形式用于Linux和W ...

TCP&sol;IP协议(5):传输层之TCP

一.TCP报文 上图为TCP报文的格式,可以看到TCP头部占20个字节,其中红色圆圈中每一项占一位,表示TCP报文的类型,置1表示该项有效. SYN表示建立连接.    FIN表示关闭连接.    A ...

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
仅仅是 一个python编程的练习 def TenGreenBottles(): for i in range (10,0,-1): print str(i)+" green bottles standing on the wall," print str(i)+" green bottles standing on the wall," print "And if 1 green bottles should accidently fall," print "there'll be "+str(i-1)+" green bottles standing on the wall." print "" def AltATenGreenBottles(): for i in range (10,2,-1): print str(i)+" green bottles standing on the wall," print str(i)+" green bottles standing on the wall," print "And if 1 green bottle should accidently fall," print "there'll be "+str(i-1)+" green bottles standing on the wall." print "" print "2 green bottles standing on the wall" print "2 green bottles standing on the wall" print "And if 1 green bottle should accidently fall," print "there'll be 1 green bottle standing on the wall" print "" print "1 green bottle standing on the wall" print "1 green bottle standing on the wall" print "And if 1 green bottle should accidently fall," print "there'll be no green bottles standing on the wall" def MyFavouriteTenGreenBottles(): for i in range (10,0,-1): if (i>1): print str(i)+" green bottles standing on the wall," print str(i)+" green bottles standing on the wall," else: print "1 green bottle standing on the wall," print "1 green bottle standing on the wall," print "And if 1 green bottle should accidently fall," if ((i-1)==1): print "there'll be 1 green bottle standing on the wall." elif ((i-1)==0): print "there'll be no green bottles standing on the wall." else: print "there'll be "+str(i-1)+" green bottles standing on the wall." print "" def xGreenBottles(x): for i in range (x,0,-1): if (i>1): print str(i)+" green bottles standing on the wall," print str(i)+" green bottles standing on the wall," else: print "1 green bottle standing on the wall," print "1 green bottle standing on the wall," print "And if 1 green bottle should accidently fall," if ((i-1)==1): print "there'll be 1 green bottle standing on the wall." elif ((i-1)==0): print "there'll be no green bottles standing on the wall." else: print "there'll be "+str(i-1)+" green bottles standing on the wall." print "" def xyGreenBottles(x,y): for i in range (x,0,-y): if (i>1): print str(i)+" green bottles standing on the wall," print str(i)+" green bottles standing on the wall," else: print "1 green bottle standing on the wall," print "1 green bottle standing on the wall," if (y==1): print "And if 1 green bottle should accidently fall," elif (y<i): print "And if "+str(y)+" green bottles should accidently fall," else: print "And if "+str(i)+" green bottles should accidently fall," if ((i-y)==1): print "there'll be 1 green bottle standing on the wall." elif ((i-y)<0): print "there'll be no green bottles standing on the wall." else: print "there'll be "+str(i-y)+" green bottles standing on the wall." print ""

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值