所以我非常讨厌,我在文件夹中的某个地方找到了这个python代码,因为我是从前一段时间开始学习python的,所以今天我需要此代码来上课。问题是,它不打印任何内容,只是表明它没有问题。你能帮助我吗?我需要对代码进行编码并对输出进行编码,如果您可以引导我了解缺少什么代码行或确实有什么问题。.谢谢
def square(n):
word = int(raw_input('Enter number here: '))
if len(word) > 0:
squared = n ** 2
print ("%d squared is %d" %(n,squared))
答案 0 :(得分:1)
首先,使用Python 3,您需要将raw_input
替换为input
。其次,也是最重要的一点是,整数不能与len
函数一起使用,您应该直接比较整数。要处理潜在的类型不匹配,请使用以下代码(您可以将其放入循环或进行任何其他修改)
def square():
n = input('Enter number here: ')
try:
n = int(n)
except TypeError:
print("Input is not a number")
else:
if word > 0:
squared = n ** 2
print ("%d squared is %d" %(n,squared))
# Let's call the function
square()
顺便说一句,我认为调用整数变量word
并不是很自我描述。
答案 1 :(得分:0)
我认为这会起作用:
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<script src="https://rawgit.com/jeromeetienne/AR.js/master/aframe/build/aframe-ar.min.js"></script>
<script src="https://rawgit.com/donmccurdy/aframe-extras/master/dist/aframe-extras.loaders.min.js"></script>
<body style="margin : 0px; overflow: hidden;">
<a-scene embedded vr-mode-ui="enabled: false" arjs="sourceType: webcam; trackingMethod: best; debugUIEnabled: false;">
<a-assets>
<a-asset-item id="animated-asset" src="https://raw.githubusercontent.com/nicolocarpignoli/nicolocarpignoli.github.io/master/ar-playground/models/CesiumMan.gltf"></a-asset-item>
</a-assets>
<a-marker markerhandler preset="hiro" emitevents="true" cursor="fuse: false; rayOrigin: mouse" id="animated-marker">
<a-entity position="0 0 1">
<a-entity
id="animated-model"
gltf-model="#animated-asset"
scale="3"
position="-3 0 0"
rotation="-90 0 0">
</a-entity>
</a-entity>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
<script>
AFRAME.registerComponent('markerhandler', {
init: function() {
const animatedMarker = document.querySelector("#animated-marker");
const aEntity = document.querySelector("#animated-model");
animatedMarker.addEventListener('click', function(ev, target){
const intersectedElement = ev && ev.detail && ev.detail.intersectedEl;
if (aEntity && intersectedElement === aEntity) {
alert("test");
}
});
}
});
</script>
</body>