打印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