我有这个程序计算回答特定问题所花费的时间,当答案不正确时退出while循环,但我想删除最后一次计算,所以我可以打电话min(),这不是错误的时间,对不起,如果这令人困惑.
from time import time
q = input('What do you want to type? ')
a = ' '
record = []
while a != '':
start = time()
a = input('Type: ')
end = time()
v = end-start
record.append(v)
if a == q:
print('Time taken to type name: {:.2f}'.format(v))
else:
break
for i in record:
print('{:.2f} seconds.'.format(i))
Run Code Online (Sandbox Code Playgroud) 所以在学习了一些JavaScript函数后,我想做一个猜谜游戏,这是我的代码:(编辑)
<body>
<script>
var a;
function rand(){
var a = Math.floor((Math.random()*100)+1);
}
function random() {
guess = document.getElementById('gess').value;
if(guess < a) {
document.getElementById('gus').innerHTML = 'To small!';
}
else if(guess > a) {
document.getElementById('gus').innerHTML = 'To big!';
}
else if(guess == a) {
document.getElementById('gus').innerHTML = 'Correct! The secret number is ' + a;
}
}
</script>
<h1> Guess the secret number! </h1>
<input type='text' id='gess'>
<input type='button' onClick='random()' value='Guess!'>
<input type='button' value='Reset Number' onClick='rand()'>
<br>
<p id='gus'> </p>
</body>
Run Code Online (Sandbox Code Playgroud)
我该怎么做,因为随机数(a)每次点击'猜猜'都要停止刷新,谢谢你提前!
<html>
<head>
</head>
<body>
<script>
function toD(angle) {
return angle * (180 / Math.PI);
}
var a = document.getElementById('test').innerHTML = toD(15);
</script>
<p id='test'> </p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
对不起,我不确定我是否遗漏了什么,但为什么这段代码没有运行?提前谢谢,对不起,如果这是一个愚蠢的问题!
这是我的代码:
with open('index.html', 'w') as html:
title = input('Title of the page? ').capitalize()
h2 = input('Heading for your website: ').capitalize()
p1 = input('First paragraph: ').capitalize()
p2 = input('Second paragraph: ').capitalize()
a = '''
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet">
<title> {} </title>
</head>
<body>
<center>
<h2> {} </h2>
</center>
<div id='well'>
<p style='position: relative; left: 100px'> {} </p>
<p style='position: relative; left: 100px'> {} </p>
<input type='button' value='test' onClick='Button()'>
<p id='lol'> </p>
</div>
<script>
function Button()
\{
document.getElementById('lol').innerHTML = 'hello';
\} …Run Code Online (Sandbox Code Playgroud) 这是一个问题:
给定两个单词中每个字母数相同的单词,计算出需要更改多少个字母才能从第一个单词到第二个单词.编辑距离的更复杂版本通常用于在电话和文字处理器上拼写自动校正算法以找到候选校正.
应该从用户读取这两个单词,每行一个单词.例如:
Word 1: hello
Word 2: jelly
2
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
w1 = input('Word 1: ')
w2 = input('Word 2: ')
for i in w1:
for o in w2:
print(i, o)
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
我试过这样做
while 1:
line = input('Line: ')
print(line[::-1])
Run Code Online (Sandbox Code Playgroud)
但所有这一切都颠倒了整个句子,我想知道是否有人可以帮我一个将'hello world'转换为'olleh dlrow'而不是'dlrow olleh'的程序,以及如何制作一个循环停止时输入什么都没有,或只是一个空间?先谢谢你!
这是我的代码:
line = ' '
while line != '':
line = input('Line: ')
phonic = line.split()
start = phonic[0]
start_4 = phonic [3]
a = start[0]
if start_4.startswith(a):
print('Good!')
else:
print("That's not right!")
Run Code Online (Sandbox Code Playgroud)
我想我知道,因为line = '',phonic试图分裂它,但那里什么都没有,我该如何解决?