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

猜你喜欢

转载自www.cnblogs.com/scholarly/p/9880540.html