1. import sys
  2.  
  3. def fact(n):
  4. final = n
  5. while n > 1:
  6. final *= n - 1
  7. n -= 1
  8. return final #逻辑严谨,不要忘了return
  9.  
  10. def main():
  11. t = int(sys.stdin.readline())
  12. for n in sys.stdin:
  13. print fact(int(n)) #读取String的转换是一个常见的坑
  14.  
  15. main()

//第二种,利用现成的库

  1. from math import factorial #熟悉这种调用方法
  2.  
  3. def main():
  4. t = int(raw_input())
  5. for i in range(t):
  6. print factorial(int(raw_input()))
  7.  
  8. main()

学习

  怎么调用外部的库  

错误

  函数忘了return, 思路不严谨

  读取时候忘了类型转换

    py的类型转化更为注意,比起有类型规定的C

Small factorials Solved Problem code: FCTRL2的更多相关文章

  1. Factorial Solved Problem code: FCTRL

    import sys #import psyco #很奇怪,这题用psyco就runtime error #psyco.full() def z(n): #这个应该是技巧的一种算法 r = 0 whi ...

  2. ATM Solved Problem code: HS08TES

    # ATM import sys withdraw, balance = map(float, sys.stdin.readline().strip().split()) # strip()用法去除结 ...

  3. Double Strings Solved Problem code: DOUBLE

    # Fuking silly, OTZ.... import sys def main(): n = int(raw_input()) for num in sys.stdin: if int(num ...

  4. Enormous Input Test Solved Problem code: INTEST

    import sys import psyco #一键优化库 psyco.full() def main(): n, k = map(int, sys.stdin.readline().strip() ...

  5. Cooking Schedule Problem Code: SCHEDULE(优先队列)

    Cooking Schedule Problem Code: SCHEDULE Chef is a well-known chef, and everyone wishes to taste his ...

  6. Holes in the text Add problem to Todo list Problem code: HOLES

    import sys def count_holes(letter): hole_2 = ['A', 'D', 'O', 'P', 'Q', 'R'] if letter == 'B': return ...

  7. The Lead Game Add problem to Todo list Problem code: TLG

    '''def count_lead(first, second): if first > second: return 1, first - second elif first == secon ...

  8. Turbo Sort Add problem to Todo list Problem code: TSORT

    def heap_sort(ary): n = len(ary) first = int(n / 2 - 1) for start in range(first, -1, -1): # 3~0 rev ...

  9. Use Spring Insight Developer to Analyze Code, Install it with Tomcat, and Extend it with Plugins--转载

    原文地址:http://www.tomcatexpert.com/blog/2012/12/05/use-spring-insight-developer-analyze-code-install-i ...

随机推荐

  1. MyGeneration 默认设置中没有数据库驱动

    这 个问题的出现基本上是因为MyGeneration 1.3需要的是 .Net framework 4.0,如果系统安装了 .Net 2.0的版本,安装程序执行的 regasm.exe为2.0版本下的 ...

  2. Spark学习笔记--Transformation 和 action

    转自:http://my.oschina.net/hanzhankang/blog/200275 附:各种操作的逻辑执行图 https://github.com/JerryLead/SparkInte ...

  3. Java学习笔记--通过java.net.URLConnection发送HTTP请求

    http://www.cnblogs.com/nick-huang/p/3859353.html 使用Java API发送 get请求或post请求的步骤: 1. 通过统一资源定位器(java.net ...

  4. hdu 相遇周期

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ...

  5. 负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体

    负重前行的婚纱线上路 - i天下网商-最具深度的电商知识媒体 负重前行的婚纱线上路

  6. Windows系统结构

    四种用户模式进程:1.系统支持进程,比如登录进程和会话管理器,并不是Windows服务,不有服务控制管理器启动2.服务进程,一些以Windows服务方式来运行的组件3.用户应用进程4.环境子系统服务器 ...

  7. (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...

  8. swing入门例子

    // a simple exmple that can show the basis of swing------------------------------------------------- ...

  9. DOM事件处理程序-事件对象-键盘事件

    事件流: 事件流--描述的是从页面中接受事件的顺序 IE  ---事件冒泡流:即事件最开始由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播至最不具体的那个节点(文档). Netsc ...

  10. (转)IIS5.1的安装配置并发布ASP.NET网站

    最近跟老师做一个桥梁养护系统的项目,要求用VS2008+Sql Server2000,服务器用IIS.由于之前做过的ASP.NET项目都是用的VS内置的服务器,并没有使用过IIS,第一次搭,花了几个小 ...