打印100以内3的倍数


1 # -*- coding:utf-8 -*-
2 y=0
3 for x in range(1,100):
4         if (x%3==0):
5            print(x,end=" ")
6            y+=1
7 print("Three's multiple in 100 is ",(y))

遇到的问题:

  • 怎么打印不换行?

  • 在python3.x之后,可以在print()之中加end=""来解决,可以自定义结尾字符。

  • TypeError: not all arguments converted during string formatting

  • 前面没有%d,就不需要%(y)

  • 最后一行可以换成

  •  1 print("Three's multiple in 100 is %d "%(y)) 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM