博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CS入门学习笔记1-MIT 6.00.1x
阅读量:3938 次
发布时间:2019-05-23

本文共 1031 字,大约阅读时间需要 3 分钟。

MIT 6.00.1x 第三讲

主要内容包括:

· Iteration loops
· “Guess & Check” Algorithms
· Exhaustive enumeration
· Floating point accuracy
· Bisection Search
· Newton-Raphson Algorithm

ProblemSet:In this problem, you’ll create a program that guesses a secret number!

x = int( raw_input('Enter an integer between 0 and 100:'))numGuesses = 0low = 0high = 100ans = (high + low) / 2while abs( ans - x ) >= 0:    print ('Is your secret number '+str(ans)+'?')    y = str( raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly."))    if y == 'h':        high = ans    elif y == 'l':        low = ans    elif y == 'c':        print('Game over. Your secret number was: '+ str(ans))        break    elif y =='quit':        break    else:        print('Sorry, I did not understand your input.')        ans = (high + low) / 2

我的代码在本机上跑起来没问题,在线提交之后出现了错误,应该是由于他的输入设置和我的未能匹配的缘故,暂时还不知道原因,有待寻找。

另外在写代码的过程中遇到的问题是:

当用户输入不符合判断的字符时,要如何跳转回循环中最初的语句,粗略的查了一下之后似乎python中不支持goto等功能,有待研究。

转载地址:http://pquwi.baihongyu.com/

你可能感兴趣的文章
Convert polygon faces to triangles or quadrangles
查看>>
read obj in matlab
查看>>
find out the neighbour matrix of a mesh
查看>>
Operators and special characters in matlab
查看>>
As-Conformal-As-Possible Surface Registration
查看>>
qmake Variable Reference
查看>>
Lesson 2 Gradient Desent
查看>>
find border vertex
查看>>
matlab sliced variable
查看>>
create symbolic array
查看>>
TAUCS库的编译(vs2010)
查看>>
color vector using in plotting example points and lines between corresponding vertices
查看>>
mex 里面调用matlab函数
查看>>
matlab中cuda编程中分配grid和block dimension的时候的注意事项
查看>>
GPU CUDA and MEX Programming
查看>>
arrayfun用法
查看>>
矩阵积分
查看>>
optimization on macOS
查看>>
Template-Based 3D Model Fitting Using Dual-Domain Relaxation
查看>>
install libfreenect2 on ubuntu 16.04
查看>>