使用Python 2.7.2.当我尝试导入pygame时,我收到以下错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Run Code Online (Sandbox Code Playgroud)
我不确定这意味着什么.我应该自己编译pygame吗?
我刚开始学习C并直接从一本书中复制了它.有人能告诉我为什么这不起作用?
#include <stdio.h>
int main (void)
{
int integerVar = 100;
float floatingVar = 331.79;
double doubleVar = 8.44e+11;
char charVar = "W";
_Bool boolVar = 0;
printf ("integerVar = %i\n", integerVar);
printf ("floatingVar = %f\n", floatingVar);
printf ("doubleVar = %e\n", doubleVar);
printf ("doubleVar = %g\n", doubleVar);
printf ("charVar = %c\n", charVar);
printf ("boolVar = %i\n", boolVar);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
datatypes.c: In function ‘main’:
datatypes.c:8: warning: initialization makes integer from pointer without a cast
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个ATM程序,它将钱存入一个人的账户.当该人取出提款时,它会从账户中扣除50%的附加费.我遇到的问题是在这个程序中使用整数和浮点数.我将整数帐户转换为浮点数,但是当我尝试打印语句时收到错误消息.有人能告诉我我做错了什么吗?
#include <stdio.h>
int main (void) {
int account = 2000;
int withdrawal;
float charge = 0.50;
printf ("How much money would you like to take out? ");
scanf ("%i", &withdrawal);
while (withdrawal % 5 != 0) {
printf ("Withdrawal must be divisible by 5. ");
scanf("%i", &withdrawal);
}
account = ((float) account - charge) - withdrawal;
printf("Remaining account: %.2f\n", account);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我对C相对较新.在Kochan的"C语言编程"中,我目前正在使用if-else语句.我正在尝试编写一个基本的tic-tac-toe游戏,但我遇到了一些困难.一旦玩家放置了x或o,我不确定如何保存棋盘.这是我到目前为止的代码:
#include <stdio.h>
int main (void)
{
int board = "_|_|_\n
_|_|_\n
| | \n";
int player1, player2;
printf ("Print %i", board)
printf("Player 1, it's your move:")
scanf("%i", player1)
if(player1 == "upLeft")
printf("x|_|_\n
_|_|_\n
_|_|_\n
etc.
Run Code Online (Sandbox Code Playgroud)
我还是太初学者才能实现这个功能吗?
我创建了一个简单的猜谜游戏程序.我的问题是,一旦用户输入错误的数字,我不确定如何将程序循环回程序的开头.我希望程序继续向用户询问一个数字,直到他做对了.有人能帮我吗?
#include <stdio.h>
int main (void) {
int value = 58;
int guess;
printf("Please enter a value: ");
scanf("%i", &guess);
if (guess == value) {
printf("Congratulations, you guessed the right value");
}
else if (guess > value) {
printf("That value is too high. Please guess again: ");
scanf("%i", &guess);
}
else if (guess < value) {
printf("That value is too low. Please guess again: ");
scanf("%i", &guess);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个程序,它接受一个输入的字符串并向后输出字符串.我创建了一个计算字符串中字符数的函数.有了这些信息,我创建了另一个函数,将原始数组的第一个字符放在新数组的末尾.因此,当函数中的循环完成时,新数组包含原始数组的字母但向后.然而,我遇到了一些困难.我仍然对字符数组保持警惕,我不确定我是否正确使用它们.有人可以帮帮我吗?
#include <stdio.h>
#define MAXLINE 1000
char backward(char str[], int count)
int count(char str[])
int main() {
char orig[MAXLINE];
int c;
scanf("%s", orig);
c = count(orig);
printf("%s", backward(orig, c));
return 0;
}
char backward(char str[], int count) {
char back[MAXLINE];
int i;
for(i = 0; i <= count; ++i) {
back[count] = str[i];
--count;
return back;
}
int count(char str[]) {
int i;
for (i = 0; str[i] != '\0'; ++i)
;
return i;
}
Run Code Online (Sandbox Code Playgroud)
编辑:输入:让我们说"小型货车".预期的产出将是"navinim".还没有实际的输出.我收到这个错误:
palindrome.c:8: error: expected ‘=’, …Run Code Online (Sandbox Code Playgroud)